Skip to content

Commit

Permalink
Fixed an issue where auto commit/rollback setting not persisting acro…
Browse files Browse the repository at this point in the history
…ss query tool connection change. #7091
  • Loading branch information
adityatoshniwal committed Jan 1, 2024
1 parent 740ce15 commit 5248055
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/en_US/release_notes_8_2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Bug fixes
| `Issue #7070 <https://github.com/pgadmin-org/pgadmin4/issues/7070>`_ - Fixed an issue where pgAgent job schedule dialog is not opening for edit.
| `Issue #7078 <https://github.com/pgadmin-org/pgadmin4/issues/7078>`_ - Fixed an issue where user is not able to cancel or terminate active queries from dashboard.
| `Issue #7082 <https://github.com/pgadmin-org/pgadmin4/issues/7082>`_ - Fixed browser autocomplete related issues on pgAdmin authentication related pages.
| `Issue #7091 <https://github.com/pgadmin-org/pgadmin4/issues/7091>`_ - Fixed an issue where auto commit/rollback setting not persisting across query tool connection change.
29 changes: 17 additions & 12 deletions web/pgadmin/tools/sqleditor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,19 +436,22 @@ def _init_sqleditor(trans_id, connect, sgid, sid, did, dbname=None, **kwargs):
current_app.logger.error(e)
return True, internal_server_error(errormsg=str(e)), '', ''

pref = Preferences.module('sqleditor')

if kwargs.get('auto_commit', None) is None:
kwargs['auto_commit'] = pref.preference('auto_commit').get()
if kwargs.get('auto_rollback', None) is None:
kwargs['auto_rollback'] = pref.preference('auto_rollback').get()

try:
conn = manager.connection(conn_id=conn_id,
auto_reconnect=False,
use_binary_placeholder=True,
array_to_string=True,
**({"database": dbname} if dbname is not None
else {"did": did}))
pref = Preferences.module('sqleditor')

if connect:
kwargs['auto_commit'] = pref.preference('auto_commit').get()
kwargs['auto_rollback'] = pref.preference('auto_rollback').get()

status, msg, is_ask_password, user, role, password = _connect(
conn, **kwargs)
if not status:
Expand Down Expand Up @@ -496,8 +499,8 @@ def _init_sqleditor(trans_id, connect, sgid, sid, did, dbname=None, **kwargs):
sql_grid_data = session['gridData']

# Set the value of auto commit and auto rollback specified in Preferences
command_obj.set_auto_commit(pref.preference('auto_commit').get())
command_obj.set_auto_rollback(pref.preference('auto_rollback').get())
command_obj.set_auto_commit(kwargs['auto_commit'])
command_obj.set_auto_rollback(kwargs['auto_rollback'])

# Set the value of database name, that will be used later
command_obj.dbname = dbname if dbname else None
Expand Down Expand Up @@ -540,11 +543,17 @@ def update_sqleditor_connection(trans_id, sgid, sid, did):
req_args['recreate'] == '1'):
connect = False

# Old transaction
_, _, _, trans_obj, session_obj = \
check_transaction_status(trans_id)

new_trans_id = str(secrets.choice(range(1, 9999999)))
kwargs = {
'user': data['user'],
'role': data['role'] if 'role' in data else None,
'password': data['password'] if 'password' in data else None
'password': data['password'] if 'password' in data else None,
'auto_commit': getattr(trans_obj, 'auto_commit', None),
'auto_rollback': getattr(trans_obj, 'auto_rollback', None),
}

is_error, errmsg, conn_id, version = _init_sqleditor(
Expand All @@ -555,11 +564,7 @@ def update_sqleditor_connection(trans_id, sgid, sid, did):
return errmsg
else:
try:
# Check the transaction and connection status
status, error_msg, conn, trans_obj, session_obj = \
check_transaction_status(trans_id)

status, error_msg, new_conn, new_trans_obj, new_session_obj = \
_, _, _, new_trans_obj, new_session_obj = \
check_transaction_status(new_trans_id)

new_session_obj['primary_keys'] = session_obj[
Expand Down

0 comments on commit 5248055

Please sign in to comment.