mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure sort/filter dialog should display proper message after losing database connection. Fixes #3561
This commit is contained in:
committed by
Akshay Joshi
parent
0f17b4f738
commit
25679fd542
@@ -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
|
||||
)
|
||||
|
@@ -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
|
||||
|
@@ -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.
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user