public inbox for [email protected]
help / color / mirror / Atom feedFrom: Surinder Kumar <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch]: Regarding RM#1419 - Internal Server Error displayed if create any object through simplified Chinese character
Date: Tue, 12 Jul 2016 15:27:44 +0530
Message-ID: <CAM5-9D80C1BH7xENfmrzjo+RS_=N1ijBx7chvDykBUtarSUfrA@mail.gmail.com> (raw)
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgadmin-hackers>
Hi
*What is happening in code?*
Database is created with Chinese characters successfully with ascii
values(Chinese characters converted to ascii) before saving internally.
but when database properties is retrieved by name, it fails to fetch data
and throws UnicodeError.
*Solution:*
Database name should be encoded in 'utf-8' before storing to database.
This resolved the issue.
I have tested this patch by creating database name using Japanese and
Chinese characters. It works.
Also referenced the code to *set default encoding to 'uff-8' *before start
of application.
https://github.com/joeyespo/grip/issues/86
@Ashesh/@Dave can you please review the patch?
If it looks good, we can do the same changes in case of other nodes.
Thanks,
Surinder Kumar
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
Attachments:
[application/octet-stream] RM#1419.patch (2.1K, 3-RM%231419.patch)
download | inline diff:
diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py
index b679cd6..eb75931 100644
--- a/web/pgAdmin4.py
+++ b/web/pgAdmin4.py
@@ -86,6 +86,12 @@ if not PGADMIN_RUNTIME:
(config.APP_NAME, server_port))
sys.stdout.flush()
+# To handle non-english characters set default encoding
+# to utf-8
+# Referenced from https://github.com/joeyespo/grip/issues/86
+reload(sys)
+sys.setdefaultencoding('utf-8')
+
try:
app.run(
host=config.DEFAULT_SERVER,
diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
index 1f7fd07..34007ae 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
@@ -11,6 +11,7 @@
import json
import re
+import sys
from functools import wraps
import pgadmin.browser.server_groups.servers as servers
@@ -453,6 +454,7 @@ class DatabaseView(PGChildNodeView):
)
)
try:
+ data['name'] = data['name'].encode(sys.getdefaultencoding())
# The below SQL will execute CREATE DDL only
SQL = render_template(
"/".join([self.template_path, 'create.sql']),
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
index 377e6f7..b35d932 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py
@@ -9,6 +9,7 @@
import json
import re
+import sys
from functools import wraps
import pgadmin.browser.server_groups.servers as servers
@@ -509,6 +510,7 @@ It may have been removed by another user.
)
try:
self.format_request_acls(data)
+ data['name'] = data['name'].encode(sys.getdefaultencoding())
SQL = render_template(
"/".join([self.template_path, 'sql/create.sql']),
data=data, conn=self.conn, _=gettext
view thread (8+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [pgAdmin4][Patch]: Regarding RM#1419 - Internal Server Error displayed if create any object through simplified Chinese character
In-Reply-To: <CAM5-9D80C1BH7xENfmrzjo+RS_=N1ijBx7chvDykBUtarSUfrA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox