public inbox for [email protected]
help / color / mirror / Atom feedFrom: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM3903] Query Tool Initialization Error
Date: Mon, 28 Jan 2019 14:32:07 +0530
Message-ID: <CAM9w-_n93p+1+FX=6S2ryrnehbHOGO5=qHN+dQ_Taibf9LbdOg@mail.gmail.com> (raw)
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,
view thread (2+ 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][RM3903] Query Tool Initialization Error
In-Reply-To: <CAM9w-_n93p+1+FX=6S2ryrnehbHOGO5=qHN+dQ_Taibf9LbdOg@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