public inbox for [email protected]
help / color / mirror / Atom feed[pgAdmin4][PATCH] To fix the of issue in table node
2+ messages / 1 participants
[nested] [flat]
* [pgAdmin4][PATCH] To fix the of issue in table node
@ 2017-05-09 13:36 Murtuza Zabuawala <[email protected]>
2017-05-09 14:36 ` Re: [pgAdmin4][PATCH] To fix the of issue in table node Murtuza Zabuawala <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Murtuza Zabuawala @ 2017-05-09 13:36 UTC (permalink / raw)
To: pgadmin-hackers
Hi,
PFA minor patch to fix the issue in table node where it fails to create
table when user provides numeric table name eg: 123.
RM#2284
Issue is when use json.loads() it converts string "123" into integer 123.
--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index e118cab..6a9a503 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -1417,6 +1417,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# Parse & format columns
data = self._parse_format_columns(data)
+ data['name'] = str(data['name'])
# 'coll_inherits' is Array but it comes as string from browser
# We will convert it again to list
@@ -1447,8 +1448,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return internal_server_error(errormsg=res)
# PostgreSQL truncates the table name to 63 characters.
- # Have to truncate the name like PostgreSQL to get the proper schema id
+ # Have to truncate the name like PostgreSQL to get the
+ # proper OID
CONST_MAX_CHAR_COUNT = 63
+
if len(data['name']) > CONST_MAX_CHAR_COUNT:
data['name'] = data['name'][0:CONST_MAX_CHAR_COUNT]
@@ -2129,9 +2132,12 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data['relacl'][mode], self.acl
)
- # If name if not present
+ # If name is not present in request data
if 'name' not in data:
data['name'] = old_data['name']
+ else:
+ data['name'] = str(data['name'])
+
# If name if not present
if 'schema' not in data:
data['schema'] = old_data['schema']
@@ -2310,6 +2316,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# Parse & format columns
data = self._parse_format_columns(data)
+ data['name'] = str(data['name'])
if 'foreign_key' in data:
for c in data['foreign_key']:
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
Attachments:
[text/plain] RM_2284.diff (2.1K, 3-RM_2284.diff)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index e118cab..6a9a503 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -1417,6 +1417,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# Parse & format columns
data = self._parse_format_columns(data)
+ data['name'] = str(data['name'])
# 'coll_inherits' is Array but it comes as string from browser
# We will convert it again to list
@@ -1447,8 +1448,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return internal_server_error(errormsg=res)
# PostgreSQL truncates the table name to 63 characters.
- # Have to truncate the name like PostgreSQL to get the proper schema id
+ # Have to truncate the name like PostgreSQL to get the
+ # proper OID
CONST_MAX_CHAR_COUNT = 63
+
if len(data['name']) > CONST_MAX_CHAR_COUNT:
data['name'] = data['name'][0:CONST_MAX_CHAR_COUNT]
@@ -2129,9 +2132,12 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data['relacl'][mode], self.acl
)
- # If name if not present
+ # If name is not present in request data
if 'name' not in data:
data['name'] = old_data['name']
+ else:
+ data['name'] = str(data['name'])
+
# If name if not present
if 'schema' not in data:
data['schema'] = old_data['schema']
@@ -2310,6 +2316,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# Parse & format columns
data = self._parse_format_columns(data)
+ data['name'] = str(data['name'])
if 'foreign_key' in data:
for c in data['foreign_key']:
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [pgAdmin4][PATCH] To fix the of issue in table node
2017-05-09 13:36 [pgAdmin4][PATCH] To fix the of issue in table node Murtuza Zabuawala <[email protected]>
@ 2017-05-09 14:36 ` Murtuza Zabuawala <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Murtuza Zabuawala @ 2017-05-09 14:36 UTC (permalink / raw)
To: pgadmin-hackers
Hi,
Please find updated patch.
Updated logic to convert name only if name is of type int/long/float
(Python2) or of type int/float (Python3) instead of blindly convert it to
string.
--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Tue, May 9, 2017 at 7:06 PM, Murtuza Zabuawala <
[email protected]> wrote:
> Hi,
>
> PFA minor patch to fix the issue in table node where it fails to create
> table when user provides numeric table name eg: 123.
> RM#2284
>
> Issue is when use json.loads() it converts string "123" into integer 123.
>
> --
> Regards,
> Murtuza Zabuawala
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index e118cab..b6bf7ed 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -1376,6 +1376,28 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return data
+ def check_and_convert_name_to_string(self, data):
+ """
+ This function will check and covert table to string incase
+ it is numeric
+
+ Args:
+ data: data dict
+
+ Returns:
+ Updated data dict
+ """
+ # For Python2, it can be int, long, float
+ if hasattr(str, 'decode'):
+ if isinstance(data['name'], (int, long, float)):
+ data['name'] = str(data['name'])
+ else:
+ # For Python3, it can be int, float
+ if isinstance(data['name'], (int, float)):
+ data['name'] = str(data['name'])
+ return data
+
+
@check_precondition
def create(self, gid, sid, did, scid):
"""
@@ -1417,6 +1439,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# Parse & format columns
data = self._parse_format_columns(data)
+ data = self.check_and_convert_name_to_string(data)
# 'coll_inherits' is Array but it comes as string from browser
# We will convert it again to list
@@ -1447,8 +1470,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return internal_server_error(errormsg=res)
# PostgreSQL truncates the table name to 63 characters.
- # Have to truncate the name like PostgreSQL to get the proper schema id
+ # Have to truncate the name like PostgreSQL to get the
+ # proper OID
CONST_MAX_CHAR_COUNT = 63
+
if len(data['name']) > CONST_MAX_CHAR_COUNT:
data['name'] = data['name'][0:CONST_MAX_CHAR_COUNT]
@@ -2129,9 +2154,12 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data['relacl'][mode], self.acl
)
- # If name if not present
+ # If name is not present in request data
if 'name' not in data:
data['name'] = old_data['name']
+
+ data = self.check_and_convert_name_to_string(data)
+
# If name if not present
if 'schema' not in data:
data['schema'] = old_data['schema']
@@ -2310,6 +2338,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# Parse & format columns
data = self._parse_format_columns(data)
+ data = self.check_and_convert_name_to_string(data)
if 'foreign_key' in data:
for c in data['foreign_key']:
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
Attachments:
[text/plain] RM_2284_v1.diff (3.0K, 3-RM_2284_v1.diff)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index e118cab..b6bf7ed 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -1376,6 +1376,28 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return data
+ def check_and_convert_name_to_string(self, data):
+ """
+ This function will check and covert table to string incase
+ it is numeric
+
+ Args:
+ data: data dict
+
+ Returns:
+ Updated data dict
+ """
+ # For Python2, it can be int, long, float
+ if hasattr(str, 'decode'):
+ if isinstance(data['name'], (int, long, float)):
+ data['name'] = str(data['name'])
+ else:
+ # For Python3, it can be int, float
+ if isinstance(data['name'], (int, float)):
+ data['name'] = str(data['name'])
+ return data
+
+
@check_precondition
def create(self, gid, sid, did, scid):
"""
@@ -1417,6 +1439,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# Parse & format columns
data = self._parse_format_columns(data)
+ data = self.check_and_convert_name_to_string(data)
# 'coll_inherits' is Array but it comes as string from browser
# We will convert it again to list
@@ -1447,8 +1470,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return internal_server_error(errormsg=res)
# PostgreSQL truncates the table name to 63 characters.
- # Have to truncate the name like PostgreSQL to get the proper schema id
+ # Have to truncate the name like PostgreSQL to get the
+ # proper OID
CONST_MAX_CHAR_COUNT = 63
+
if len(data['name']) > CONST_MAX_CHAR_COUNT:
data['name'] = data['name'][0:CONST_MAX_CHAR_COUNT]
@@ -2129,9 +2154,12 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data['relacl'][mode], self.acl
)
- # If name if not present
+ # If name is not present in request data
if 'name' not in data:
data['name'] = old_data['name']
+
+ data = self.check_and_convert_name_to_string(data)
+
# If name if not present
if 'schema' not in data:
data['schema'] = old_data['schema']
@@ -2310,6 +2338,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# Parse & format columns
data = self._parse_format_columns(data)
+ data = self.check_and_convert_name_to_string(data)
if 'foreign_key' in data:
for c in data['foreign_key']:
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2017-05-09 14:36 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-09 13:36 [pgAdmin4][PATCH] To fix the of issue in table node Murtuza Zabuawala <[email protected]>
2017-05-09 14:36 ` Murtuza Zabuawala <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox