public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][RM3903] Query Tool Initialization Error
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][RM3903] Query Tool Initialization Error
@ 2019-01-28 09:02 Aditya Toshniwal <[email protected]>
  2019-01-29 06:16 ` Re: [pgAdmin4][RM3903] Query Tool Initialization Error Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Aditya Toshniwal @ 2019-01-28 09:02 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,

Attached is the patch to fix "Query Tool Initialization Error" which occurs
on opening query tool for some users.
The problem was, request data was sent from client but was not read by back
end service. In flask, if you receive POST data in a request you *must* read
it before returning a response.
Also removed a dead code, which was not referred/used anywhere.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB Software Solutions | Pune
"Don't Complain about Heat, Plant a tree"


Attachments:

  [application/octet-stream] RM3903.patch (5.1K, 3-RM3903.patch)
  download | inline diff:
diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py
index 709e164f..ded06dec 100644
--- a/web/pgadmin/tools/datagrid/__init__.py
+++ b/web/pgadmin/tools/datagrid/__init__.py
@@ -306,8 +306,15 @@ def initialize_query_tool(sgid, sid, did=None):
         did: Database Id
     """
     connect = True
-    if ('recreate' in request.args and
-            request.args['recreate'] == '1'):
+    reqArgs = None
+    # Read the data if present. Skipping read may cause connection
+    # reset error if data is sent from the client
+    if request.data:
+        reqArgs = request.data
+
+    reqArgs = request.args
+    if ('recreate' in reqArgs and
+            reqArgs['recreate'] == '1'):
         connect = False
     # Create asynchronous connection using random connection id.
     conn_id = str(random.randint(1, 9999999))
diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js b/web/pgadmin/tools/datagrid/static/js/datagrid.js
index 851d53ff..ea61dd7a 100644
--- a/web/pgadmin/tools/datagrid/static/js/datagrid.js
+++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js
@@ -407,11 +407,20 @@ define('pgadmin.datagrid', [
         if (recreate) {
           baseUrl += '?recreate=1';
         }
+
+        /* Send the data only if required. Sending non required data may
+         * cause connection reset error if data is not read by flask server
+         */
+        let reqData = null;
+        if(sql_filter != '') {
+          reqData = JSON.stringify(sql_filter);
+        }
+
         $.ajax({
           url: baseUrl,
           method: 'POST',
           dataType: 'json',
-          data: JSON.stringify(sql_filter),
+          data: reqData,
           contentType: 'application/json',
         })
         .done(function(res) {
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index 78d368c9..885d02b9 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -96,7 +96,6 @@ define('tools.querytool', [
       'click #btn-include-filter': 'on_include_filter',
       'click #btn-exclude-filter': 'on_exclude_filter',
       'click #btn-remove-filter': 'on_remove_filter',
-      'click #btn-apply': 'on_apply',
       'click #btn-cancel': 'on_cancel',
       'click #btn-copy-row': 'on_copy_row',
       'click #btn-paste-row': 'on_paste_row',
@@ -1475,18 +1474,6 @@ define('tools.querytool', [
       );
     },
 
-    // Callback function for ok button click.
-    on_apply: function() {
-      var self = this;
-
-      // Trigger the apply_filter signal to the SqlEditorController class
-      self.handler.trigger(
-        'pgadmin-sqleditor:button:apply_filter',
-        self,
-        self.handler
-      );
-    },
-
     // Callback function for cancel button click.
     on_cancel: function() {
       $('#filter').addClass('d-none');
@@ -2084,7 +2071,6 @@ define('tools.querytool', [
         self.on('pgadmin-sqleditor:button:include_filter', self._include_filter, self);
         self.on('pgadmin-sqleditor:button:exclude_filter', self._exclude_filter, self);
         self.on('pgadmin-sqleditor:button:remove_filter', self._remove_filter, self);
-        self.on('pgadmin-sqleditor:button:apply_filter', self._apply_filter, self);
         self.on('pgadmin-sqleditor:button:copy_row', self._copy_row, self);
         self.on('pgadmin-sqleditor:button:paste_row', self._paste_row, self);
         self.on('pgadmin-sqleditor:button:limit', self._set_limit, self);
@@ -3264,49 +3250,6 @@ define('tools.querytool', [
         });
       },
 
-      // This function will apply the filter.
-      _apply_filter: function() {
-        var self = this,
-          sql = self.gridView.filter_obj.getValue();
-
-        self.trigger(
-          'pgadmin-sqleditor:loading-icon:show',
-          gettext('Applying the filter...')
-        );
-
-        // Make ajax call to include the filter by selection
-        $.ajax({
-          url: url_for('sqleditor.apply_filter', {
-            'trans_id': self.transId,
-          }),
-          method: 'POST',
-          contentType: 'application/json',
-          data: JSON.stringify(sql),
-        })
-        .done(function(res) {
-          self.trigger('pgadmin-sqleditor:loading-icon:hide');
-          setTimeout(
-            function() {
-              if (res.data.status) {
-                $('#filter').addClass('d-none');
-                $('#editor-panel').removeClass('sql-editor-busy-fetching');
-                // Refresh the sql grid
-                queryToolActions.executeQuery(self);
-              } else {
-                alertify.alert(gettext('Apply Filter Error'), res.data.result);
-              }
-            }, 10
-          );
-        })
-        .fail(function(e) {
-          self.trigger('pgadmin-sqleditor:loading-icon:hide');
-          let msg = httpErrorHandler.handleQueryToolAjaxError(
-            pgAdmin, self, e, '_apply_filter', [], true
-          );
-          alertify.alert(gettext('Apply Filter Error'), msg);
-        });
-      },
-
       // This function will copy the selected row.
       _copy_row: copyData,
 


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [pgAdmin4][RM3903] Query Tool Initialization Error
  2019-01-28 09:02 [pgAdmin4][RM3903] Query Tool Initialization Error Aditya Toshniwal <[email protected]>
@ 2019-01-29 06:16 ` Akshay Joshi <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Akshay Joshi @ 2019-01-29 06:16 UTC (permalink / raw)
  To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers

Thanks patch applied.

On Mon, Jan 28, 2019 at 2:32 PM Aditya Toshniwal <
[email protected]> wrote:

> Hi Hackers,
>
> Attached is the patch to fix "Query Tool Initialization Error" which
> occurs on opening query tool for some users.
> The problem was, request data was sent from client but was not read by
> back end service. In flask, if you receive POST data in a request you
> *must* read it before returning a response.
> Also removed a dead code, which was not referred/used anywhere.
>
> Kindly review.
>
> --
> Thanks and Regards,
> Aditya Toshniwal
> Software Engineer | EnterpriseDB Software Solutions | Pune
> "Don't Complain about Heat, Plant a tree"
>


-- 
*Akshay Joshi*

*Sr. Software Architect *



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


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-01-29 06:16 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28 09:02 [pgAdmin4][RM3903] Query Tool Initialization Error Aditya Toshniwal <[email protected]>
2019-01-29 06:16 ` Akshay Joshi <[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