Subject: [pgAdmin4][Patch] - RM 3836 VACUUM FULL FREEZE ANALYZE VERBOSE syntax error on PostgreSQL 11

From: Akshay Joshi <[email-masked]>
Date: Wed, 9 Jan 2019 18:46:17 +0530

Hi Hackers,

Attached is the patch to fix RM #3836 VACUUM FULL FREEZE ANALYZE VERBOSE
syntax error on PostgreSQL 11. Order of commands has been changed in
PostgreSQL 11 "https://github.com/postgres/postgres
/commit/921059bd66c7fb1230c705d3b1a65940800c4cbb"

Please review it.

-- 
*Akshay Joshi*

*Sr. Software Architect *

*Phone: +91 20-3058-9517Mobile: +91 976-788-8246*

---

From: Dave Page <[email-masked]>
Date: Thu, 10 Jan 2019 12:26:38 +0530

Hi

> /commit/921059bd66c7fb1230c705d3b1a65940800c4cbb"

I tried to test this, and got what looks like the same issue that we looked
at the other day with Import/Export. Can you look at it please?

2019-01-10 12:25:02,044: INFO werkzeug: 127.0.0.1 - - [10/Jan/2019
12:25:02] "POST /maintenance/job/2/12669 HTTP/1.1" 500 -
2019-01-10 12:25:02,051: ERROR werkzeug: Error on request:
Traceback (most recent call last):
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/werkzeug/serving.py",
line 270, in run_wsgi
    execute(self.server.app)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/werkzeug/serving.py",
line 258, in execute
    application_iter = app(environ, start_response)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/app.py",
line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/app.py",
line 1985, in wsgi_app
    response = self.handle_exception(e)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/app.py",
line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/_compat.py",
line 33, in reraise
    raise value
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/app.py",
line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/app.py",
line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/app.py",
line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/_compat.py",
line 33, in reraise
    raise value
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/app.py",
line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask/app.py",
line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/flask_login.py",
line 792, in decorated_view
    return func(*args, **kwargs)
  File
"/Users/dpage/git/pgadmin4/web/pgadmin/tools/maintenance/__init__.py", line
179, in create_maintenance_job
    data = json.loads(data['data'][0], encoding='utf-8')
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/simplejson/__init__.py",
line 535, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/simplejson/decoder.py",
line 370, in decode
    obj, end = self.raw_decode(s)
  File
"/Users/dpage/.virtualenvs/pgadmin4/lib/python3.6/site-packages/simplejson/decoder.py",
line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting property name enclosed in
double quotes or '}': line 1 column 2 (char 1)

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

---

From: Akshay Joshi <[email-masked]>
Date: Thu, 10 Jan 2019 12:48:38 +0530

Hi

Attached is the modified patch. I have fixed the similar code for Backup
and Restore as well along with this patch.

On Thu, Jan 10, 2019 at 12:26 PM Dave Page <[email-masked]> wrote:

> I tried to test this, and got what looks like the same issue that we
> looked at the other day with Import/Export. Can you look at it please?
>

-- 
*Akshay Joshi*

*Phone: +91 20-3058-9517Mobile: +91 976-788-8246*
diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py
index c55390db..60bfd5bf 100644
--- a/web/pgadmin/tools/backup/__init__.py
+++ b/web/pgadmin/tools/backup/__init__.py
@@ -276,9 +276,7 @@ def create_backup_objects_job(sid):
         None
     """
     if request.form:
-        # Convert ImmutableDict to dict
-        data = dict(request.form)
-        data = json.loads(data['data'][0], encoding='utf-8')
+        data = json.loads(request.form['data'], encoding='utf-8')
     else:
         data = json.loads(request.data, encoding='utf-8')
 
diff --git a/web/pgadmin/tools/maintenance/__init__.py b/web/pgadmin/tools/maintenance/__init__.py
index 0e806d97..6ae0159e 100644
--- a/web/pgadmin/tools/maintenance/__init__.py
+++ b/web/pgadmin/tools/maintenance/__init__.py
@@ -174,9 +174,7 @@ def create_maintenance_job(sid, did):
         None
     """
     if request.form:
-        # Convert ImmutableDict to dict
-        data = dict(request.form)
-        data = json.loads(data['data'][0], encoding='utf-8')
+        data = json.loads(request.form['data'], encoding='utf-8')
     else:
         data = json.loads(request.data, encoding='utf-8')
 
diff --git a/web/pgadmin/tools/maintenance/templates/maintenance/sql/command.sql b/web/pgadmin/tools/maintenance/templates/maintenance/sql/command.sql
index 5532d6cc..dfaab725 100644
--- a/web/pgadmin/tools/maintenance/templates/maintenance/sql/command.sql
+++ b/web/pgadmin/tools/maintenance/templates/maintenance/sql/command.sql
@@ -1,5 +1,5 @@
 {% if data.op == "VACUUM" %}
-VACUUM{% if data.vacuum_full %} FULL{% endif %}{% if data.vacuum_freeze %} FREEZE{% endif %}{% if data.vacuum_analyze %} ANALYZE{% endif %}{% if data.verbose %} VERBOSE{% endif %}{% if data.schema %} {{ conn|qtIdent(data.schema) }}.{{ conn|qtIdent(data.table) }}{% endif %};
+VACUUM{% if data.vacuum_full %} FULL{% endif %}{% if data.vacuum_freeze %} FREEZE{% endif %}{% if data.verbose %} VERBOSE{% endif %}{% if data.vacuum_analyze %} ANALYZE{% endif %}{% if data.schema %} {{ conn|qtIdent(data.schema) }}.{{ conn|qtIdent(data.table) }}{% endif %};
 {% endif %}
 {% if data.op == "ANALYZE" %}
 ANALYZE{% if data.verbose %} VERBOSE{% endif %}{% if data.schema %} {{ conn|qtIdent(data.schema, data.table) }}{% endif %};
diff --git a/web/pgadmin/tools/restore/__init__.py b/web/pgadmin/tools/restore/__init__.py
index 50eacc14..bcaf1da2 100644
--- a/web/pgadmin/tools/restore/__init__.py
+++ b/web/pgadmin/tools/restore/__init__.py
@@ -183,9 +183,7 @@ def create_restore_job(sid):
         None
     """
     if request.form:
-        # Convert ImmutableDict to dict
-        data = dict(request.form)
-        data = json.loads(data['data'][0], encoding='utf-8')
+        data = json.loads(request.form['data'], encoding='utf-8')
     else:
         data = json.loads(request.data, encoding='utf-8')

---

From: Dave Page <[email-masked]>
Date: Thu, 10 Jan 2019 15:31:14 +0530

Thanks - applied!

On Thu, Jan 10, 2019 at 12:48 PM Akshay Joshi <[email-masked]>
wrote:

>> On Wed, Jan 9, 2019 at 6:46 PM Akshay Joshi <
>> [email-masked]> wrote:
>>
>>> Hi Hackers,
>>>