Hi,

I have resolved the issue and patch is attached with this mail.
Please review it and let me know in case any issues.

Regards,
Sanket Mehta
Sr Software engineer
Enterprisedb

On Mon, Jun 6, 2016 at 4:23 PM, <redm...@postgresql.org> wrote:

> Issue #1292 has been updated by Sanket Mehta.
>
>    - *Assignee* set to *Sanket Mehta*
>
> ------------------------------
> Bug #1292: ERROR: template database "!@#$%^&*()_+{}|:"<>?=-\\][';/.," does
> not exist message throws if template database contain special charterers
> <https://redmine.postgresql.org/issues/1292#change-2501>
>
>    - Author: Fahar Abbas
>    - Status: In Progress
>    - Priority: Normal
>    - Assignee: Sanket Mehta
>    - Category:
>    - Target version: 1.0 Beta 1
>
> Commit ID:
> -----------
> commit 954163b4957c1dce89c0632d009b845cbe90faf4
>
> Browser version:
> ----------------
> Firefox 45.0.2
>
> Python version:
> ----------------
> 3.5.1+
>
> Platforms:
> All
>
> ERROR: template database "!@#$%^&*()_+{}|:"<>?=-\\][';/.," does not exist
> message throws if user try to create database with template database that
> name contain special charterers.
>
> Please note that this issue is not reproducible in other template
> databases that name is simple one.
>
> Please note that this is not reproduce in pgAdmin3.
>
> Steps:
>
> 1. Install pgAdmin4 on Ubuntu 16.04
> 2. Install PG-9.6-beta 1 installer
> 3. Expand database node
> 4. give it's name !#$%^&*()_+{}|:"<>?=-\][';/.,
> 5. Database created successfully
> 6. Again create new database and give it's name abcd
> 7. Click on definition tab
> 8. select template database !#$%^&*()_+{}|:"<>?=-\][';/.,
> 9. Click on Save button
> Files Screen Shot 2016-06-02 at 10.25.34 am.png
> <https://redmine.postgresql.org/attachments/download/1197/Screen%20Shot%202016-06-02%20at%2010.25.34%20am.png>
> (1020 KB)
> Screen Shot 2016-06-02 at 10.26.01 am.png
> <https://redmine.postgresql.org/attachments/download/1198/Screen%20Shot%202016-06-02%20at%2010.26.01%20am.png>
> (1.03 MB)
> ------------------------------
>
> You have received this notification because you have either subscribed to
> it, or are involved in it.
> To change your notification preferences, please click here:
> https://redmine.postgresql.org/my/account
>
diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
index 5084d88..261e3d2 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py
@@ -447,6 +447,24 @@ class DatabaseView(PGChildNodeView):
                     )
                 )
         try:
+            # Fetch template name from oid is specified
+            if 'template' in data:
+                SQL = render_template(
+                    "/".join([self.template_path,'properties.sql']),
+                    did=data['template'], conn=self.conn
+                )
+
+                status, res = self.conn.execute_dict(SQL)
+                if not status:
+                    return internal_server_error(errormsg=status)
+
+                if len(res['rows']) == 0:
+                    return gone(
+                        _("Could not find the database on the server.")
+                    )
+
+                data['template'] = res['rows'][0]['name']
+
             # The below SQL will execute CREATE DDL only
             SQL = render_template(
                 "/".join([self.template_path, 'create.sql']),
@@ -709,6 +727,24 @@ class DatabaseView(PGChildNodeView):
                     data[aclcol], allowedacl['acl']
                     )
 
+        # Fetch template name from oid is specified
+        if 'template' in data:
+            SQL = render_template(
+                "/".join([self.template_path, 'properties.sql']),
+                did=data['template'], conn=self.conn
+            )
+
+            status, res = self.conn.execute_dict(SQL)
+            if not status:
+                return internal_server_error(errormsg=status)
+
+            if len(res['rows']) == 0:
+                return gone(
+                    _("Could not find the database on the server.")
+                )
+
+            data['template'] = res['rows'][0]['name']
+
         SQL = render_template(
             "/".join([self.template_path, 'create.sql']),
             data=data, conn=self.conn
diff --git a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js
index 8441b0c..34b9ed7 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js
@@ -240,7 +240,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
           id: 'template', label: '{{ _('Template') }}',
           editable: false, type: 'text', group: 'Definition',
           disabled: function(m) { return !m.isNew(); },
-          control: 'node-list-by-name', node: 'database', cache_level: 'server'
+          control: 'node-list-by-id', node: 'database', cache_level: 'server'
         },{
           id: 'spcname', label: '{{ _('Tablespace') }}',
           editable: false, type: 'text', group: 'Definition',
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to