diff --git a/docs/en_US/release_notes_3_3.rst b/docs/en_US/release_notes_3_3.rst index f0456a5c6..77b625822 100644 --- a/docs/en_US/release_notes_3_3.rst +++ b/docs/en_US/release_notes_3_3.rst @@ -25,4 +25,5 @@ Bug fixes | `Bug #3528 `_ - Handle connection errors properly in the query tool. | `Bug #3547 `_ - Make session implementation thread safe | `Bug #3558 `_ - Fix sort/filter dialog editing issue. +| `Bug #3561 `_ - Ensure sort/filter dialog should display proper message after losing database connection. | `Bug #3578 `_ - Ensure sql for Role should be visible in SQL panel for GPDB. diff --git a/web/pgadmin/static/js/sqleditor/filter_dialog.js b/web/pgadmin/static/js/sqleditor/filter_dialog.js index 48862924c..52c566b72 100644 --- a/web/pgadmin/static/js/sqleditor/filter_dialog.js +++ b/web/pgadmin/static/js/sqleditor/filter_dialog.js @@ -7,17 +7,32 @@ import Backform from 'pgadmin.backform'; import axios from 'axios'; import queryToolActions from 'sources/sqleditor/query_tool_actions'; import filterDialogModel from 'sources/sqleditor/filter_dialog_model'; +import {handleQueryToolAjaxError} from 'sources/sqleditor/query_tool_http_error_handler'; let FilterDialog = { - 'dialog': function(handler) { + geturl: function(transId, reconnect) { + let url = url_for('sqleditor.get_filter_data', { + 'trans_id': transId, + }); + + if(reconnect) { + url += '?connect=1'; + } + + return url; + }, + + 'dialog': function(handler, reconnect) { let title = gettext('Sort/Filter options'); - axios.get( - url_for('sqleditor.get_filter_data', { - 'trans_id': handler.transId, - }), - { headers: {'Cache-Control' : 'no-cache'} } - ).then(function (res) { - let response = res.data.data.result; + + $.ajax({ + url: this.geturl(handler.transId, reconnect), + headers: { + 'Cache-Control' : 'no-cache', + }, + }) + .done(function (res) { + let response = res.data.result; // Check the alertify dialog already loaded then delete it to clear // the cache @@ -234,6 +249,9 @@ let FilterDialog = { }); Alertify.filterDialog(title).resizeTo('65%', '60%'); + }) + .fail(function(e) { + handleQueryToolAjaxError(pgAdmin, handler, e, '_show_filter', [], true); }); }, }; diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 9d8a256c3..3f0055dec 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -1526,7 +1526,11 @@ def get_filter_data(trans_id): Args: trans_id: unique transaction id """ - return FilterDialog.get(*check_transaction_status(trans_id)) + + status, error_msg, conn, trans_obj, session_ob = \ + check_transaction_status(trans_id) + + return FilterDialog.get(status, error_msg, conn, trans_obj, session_ob) @blueprint.route( @@ -1541,8 +1545,12 @@ def set_filter_data(trans_id): Args: trans_id: unique transaction id """ + + status, error_msg, conn, trans_obj, session_ob = \ + check_transaction_status(trans_id) + return FilterDialog.save( - *check_transaction_status(trans_id), + status, error_msg, conn, trans_obj, session_ob, request=request, trans_id=trans_id ) diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py index aa9f3c651..6659e3dce 100644 --- a/web/pgadmin/tools/sqleditor/command.py +++ b/web/pgadmin/tools/sqleditor/command.py @@ -550,45 +550,40 @@ class TableCommand(GridCommand): all_sorted_columns = [] data_sorting = self.get_data_sorting() all_columns = [] - if conn.connected(): + # Fetch the primary key column names + query = render_template( + "/".join([self.sql_path, 'primary_keys.sql']), + obj_id=self.obj_id + ) - # Fetch the primary key column names - query = render_template( - "/".join([self.sql_path, 'primary_keys.sql']), - obj_id=self.obj_id + status, result = conn.execute_dict(query) + + if not status: + raise Exception(result) + + for row in result['rows']: + all_columns.append(row['attname']) + all_sorted_columns.append( + { + 'name': row['attname'], + 'order': self.get_pk_order() + } ) - status, result = conn.execute_dict(query) - if not status: - raise Exception(result) + # Fetch the rest of the column names + query = render_template( + "/".join([self.sql_path, 'get_columns.sql']), + obj_id=self.obj_id + ) + status, result = conn.execute_dict(query) + if not status: + raise Exception(result) - for row in result['rows']: + for row in result['rows']: + # Only append if not already present in the list + if row['attname'] not in all_columns: all_columns.append(row['attname']) - all_sorted_columns.append( - { - 'name': row['attname'], - 'order': self.get_pk_order() - } - ) - # Fetch the rest of the column names - query = render_template( - "/".join([self.sql_path, 'get_columns.sql']), - obj_id=self.obj_id - ) - status, result = conn.execute_dict(query) - if not status: - raise Exception(result) - - for row in result['rows']: - # Only append if not already present in the list - if row['attname'] not in all_columns: - all_columns.append(row['attname']) - else: - raise Exception( - gettext('Not connected to server or connection with the ' - 'server has been closed.') - ) # If user has custom data sorting then pass as it as it is if data_sorting and len(data_sorting) > 0: all_sorted_columns = data_sorting diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index 0a3a2051c..0fd89c5f0 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -3022,8 +3022,17 @@ define('tools.querytool', [ // This function will show the filter in the text area. _show_filter: function() { - let self = this; - FilterHandler.dialog(self); + let self = this, + reconnect = false; + + /* When server is disconnected and connected, connection is lost, + * To reconnect pass true + */ + if (arguments.length > 0 && + arguments[arguments.length - 1] == 'connect') { + reconnect = true; + } + FilterHandler.dialog(self, reconnect); }, // This function will include the filter by selection. diff --git a/web/pgadmin/tools/sqleditor/utils/filter_dialog.py b/web/pgadmin/tools/sqleditor/utils/filter_dialog.py index d7064979f..1bfa2e73a 100644 --- a/web/pgadmin/tools/sqleditor/utils/filter_dialog.py +++ b/web/pgadmin/tools/sqleditor/utils/filter_dialog.py @@ -11,9 +11,11 @@ import pickle import simplejson as json from flask_babelex import gettext +from flask import current_app from pgadmin.utils.ajax import make_json_response, internal_server_error from pgadmin.tools.sqleditor.utils.update_session_grid_transaction import \ update_session_grid_transaction +from pgadmin.utils.exception import ConnectionLost, SSHTunnelConnectionLost class FilterDialog(object): @@ -32,7 +34,16 @@ class FilterDialog(object): if status and conn is not None and \ trans_obj is not None and session_obj is not None: msg = gettext('Success') - columns, column_list = trans_obj.get_all_columns_with_order(conn) + + try: + columns, column_list = \ + trans_obj.get_all_columns_with_order(conn) + except (ConnectionLost, SSHTunnelConnectionLost): + raise + except Exception as e: + current_app.logger.error(e) + raise + sql = trans_obj.get_filter() else: status = False