Skip to content

Commit 97984eb

Browse files
authored
Fix an issue where, after a database disconnection, the server would disconnect, and the reconnect dialog would repeatedly appear when clicking the Execute button. #8607
1 parent c46fd30 commit 97984eb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ def initialize_viewdata(trans_id, cmd_type, obj_type, sgid, sid, did, obj_id):
267267
command_obj.set_data_sorting(
268268
dict(data_sorting=old_trans_obj._data_sorting), True)
269269

270+
# Set the value of database name, that will be used later
271+
command_obj.dbname = conn.db if conn.db else None
272+
270273
# Use pickle to store the command object which will be used later by the
271274
# sql grid module.
272275
sql_grid_data[str(trans_id)] = {
@@ -781,7 +784,9 @@ def check_transaction_status(trans_id, auto_comp=False):
781784
conn_id=conn_id,
782785
auto_reconnect=False,
783786
use_binary_placeholder=True,
784-
array_to_string=True
787+
array_to_string=True,
788+
**({"database": trans_obj.dbname} if hasattr(
789+
trans_obj, 'dbname') else {})
785790
)
786791
except (ConnectionLost, SSHTunnelConnectionLost, CryptKeyMissing):
787792
raise
@@ -790,11 +795,7 @@ def check_transaction_status(trans_id, auto_comp=False):
790795
return False, internal_server_error(errormsg=str(e)), None, None, None
791796

792797
if connect and conn and not conn.connected():
793-
status, errmsg = conn.connect()
794-
if not status:
795-
current_app.logger.error(errmsg)
796-
return (False, internal_server_error(errormsg=str(errmsg)),
797-
None, None, None)
798+
conn.connect()
798799

799800
return True, None, conn, trans_obj, session_obj
800801

@@ -832,15 +833,18 @@ def start_view_data(trans_id):
832833
try:
833834
manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
834835
trans_obj.sid)
835-
default_conn = manager.connection(did=trans_obj.did)
836+
default_conn = manager.connection(did=trans_obj.did,
837+
** ({"database": trans_obj.dbname}
838+
if hasattr(trans_obj, 'dbname')
839+
else {}))
836840
except (ConnectionLost, SSHTunnelConnectionLost) as e:
837841
raise
838842
except Exception as e:
839843
current_app.logger.error(e)
840844
return internal_server_error(errormsg=str(e))
841845

842846
# Connect to the Server if not connected.
843-
if not default_conn.connected():
847+
if not conn.connected() or not default_conn.connected():
844848
# This will check if view/edit data tool connection is lost or not,
845849
# if lost then it will reconnect
846850
status, error_msg, conn, trans_obj, session_obj, response = \

0 commit comments

Comments
 (0)