Ensure changes to Query Tool settings from the Preferences dialogue are applied before executing queries. Fixes #3657

pull/14/head
Aditya Toshniwal 2018-09-19 16:50:11 +01:00 committed by Dave Page
parent 6a46e43567
commit 1b20831338
3 changed files with 37 additions and 16 deletions

View File

@ -22,4 +22,5 @@ Bug fixes
| `Bug #3596 <https://redmine.postgresql.org/issues/3596>`_ - Fix support for the CLOB datatype in EPAS.
| `Bug #3607 <https://redmine.postgresql.org/issues/3607>`_ - Fix logic around validation and highlighting of Sort/Filter in the Query Tool.
| `Bug #3630 <https://redmine.postgresql.org/issues/3630>`_ - Ensure auto-complete works for objects in schemas other than public and pg_catalog.
| `Bug #3657 <https://redmine.postgresql.org/issues/3657>`_ - Ensure changes to Query Tool settings from the Preferences dialogue are applied before executing queries.

View File

@ -308,6 +308,15 @@ def start_query_tool(trans_id):
connect = 'connect' in request.args and request.args['connect'] == '1'
# Preferences can be changed from outside.
# Get the latest preferences for auto commit, rollback,etc. before
# executing the query
error_msg = set_trans_preferences(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
return StartRunningQuery(blueprint, current_app.logger).execute(
sql, trans_id, session, connect
)
@ -326,6 +335,27 @@ def extract_sql_from_network_parameters(request_data, request_arguments,
return request_arguments or request_form_data
def set_trans_preferences(trans_id):
# Check the transaction and connection status
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
return error_msg
if status and conn is not None and \
trans_obj is not None and session_obj is not None:
# Call the set_auto_commit and set_auto_rollback method of
# transaction object
trans_obj.set_auto_commit(blueprint.auto_commit.get())
trans_obj.set_auto_rollback(blueprint.auto_rollback.get())
# As we changed the transaction object we need to
# restore it and update the session variable.
session_obj['command_obj'] = pickle.dumps(trans_obj, -1)
update_session_grid_transaction(trans_id, session_obj)
@blueprint.route(
'/query_tool/preferences/<int:trans_id>',
methods=["GET", "PUT"], endpoint='query_tool_preferences'
@ -339,27 +369,13 @@ def preferences(trans_id):
trans_id: unique transaction id
"""
if request.method == 'GET':
# Check the transaction and connection status
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)
error_msg = set_trans_preferences(trans_id)
if error_msg == gettext('Transaction ID not found in the session.'):
return make_json_response(success=0, errormsg=error_msg,
info='DATAGRID_TRANSACTION_REQUIRED',
status=404)
if status and conn is not None and \
trans_obj is not None and session_obj is not None:
# Call the set_auto_commit and set_auto_rollback method of
# transaction object
trans_obj.set_auto_commit(blueprint.auto_commit.get())
trans_obj.set_auto_rollback(blueprint.auto_rollback.get())
# As we changed the transaction object we need to
# restore it and update the session variable.
session_obj['command_obj'] = pickle.dumps(trans_obj, -1)
update_session_grid_transaction(trans_id, session_obj)
return make_json_response(
data={
'explain_verbose': blueprint.explain_verbose.get(),

View File

@ -23,13 +23,17 @@ class StartQueryTool(BaseTestGenerator):
calls the needed functions
"""
@patch('pgadmin.tools.sqleditor.set_trans_preferences')
@patch('pgadmin.tools.sqleditor.extract_sql_from_network_parameters')
def runTest(self, extract_sql_from_network_parameters_mock):
def runTest(self, extract_sql_from_network_parameters_mock,
set_trans_preferences):
"""Check correct function is called to handle to run query."""
extract_sql_from_network_parameters_mock.return_value = \
'transformed sql'
set_trans_preferences.return_value = ''
with patch.object(StartRunningQuery,
'execute',
return_value='some result'