diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py
index 686ff948..f09ff274 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -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(),
diff --git a/web/pgadmin/tools/sqleditor/tests/test_start_query_tool.py b/web/pgadmin/tools/sqleditor/tests/test_start_query_tool.py
index c2ff21c5..ee1fa8eb 100644
--- a/web/pgadmin/tools/sqleditor/tests/test_start_query_tool.py
+++ b/web/pgadmin/tools/sqleditor/tests/test_start_query_tool.py
@@ -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'
