From 8be65ceb7befa4863d2fcaa72dcddac5ef585ca0 Mon Sep 17 00:00:00 2001 From: Anil Sahoo Date: Tue, 19 Nov 2024 15:44:40 +0530 Subject: [PATCH] Fixed an issue related to the query tool update connection after the server disconnected from the object explorer. #7865 --- web/pgadmin/browser/server_groups/servers/__init__.py | 2 +- web/pgadmin/tools/sqleditor/__init__.py | 11 ++++++++--- web/pgadmin/utils/driver/psycopg3/connection.py | 5 ++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py index 300308402..3a9d1fecc 100644 --- a/web/pgadmin/browser/server_groups/servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/__init__.py @@ -1388,7 +1388,7 @@ class ServerNode(PGChildNodeView): If Yes, connect the server and return connection. If No, Raise HTTP error and ask for the password. - In case of 'Save Password' request from user, excrypted Password + In case of 'Save Password' request from user, encrypted Password will be stored in the respected server database and establish the connection OR just connect the server and do not store the password. diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 8b7f17f8a..66c0101da 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -406,10 +406,11 @@ def _connect(conn, **kwargs): user = kwargs['user'] role = kwargs['role'] if kwargs['role'] else None password = kwargs['password'] if kwargs['password'] else None + encpass = kwargs['encpass'] if kwargs['encpass'] else None is_ask_password = True if user: status, msg = conn.connect(user=user, role=role, - password=password) + password=password, encpass=encpass) else: status, msg = conn.connect(**kwargs) @@ -424,9 +425,14 @@ def _init_sqleditor(trans_id, connect, sgid, sid, did, dbname=None, **kwargs): kwargs.pop('conn_id') conn_id_ac = str(secrets.choice(range(1, 9999999))) - + server = Server.query.filter_by(id=sid).first() manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid) + if kwargs.get('password', None) is None: + kwargs['encpass'] = server.password + else: + kwargs['encpass'] = None + if did is None: did = manager.did try: @@ -459,7 +465,6 @@ def _init_sqleditor(trans_id, connect, sgid, sid, did, dbname=None, **kwargs): if not status: current_app.logger.error(msg) if is_ask_password: - server = Server.query.filter_by(id=sid).first() return True, make_json_response( success=0, status=428, diff --git a/web/pgadmin/utils/driver/psycopg3/connection.py b/web/pgadmin/utils/driver/psycopg3/connection.py index 74c63762a..df1166392 100644 --- a/web/pgadmin/utils/driver/psycopg3/connection.py +++ b/web/pgadmin/utils/driver/psycopg3/connection.py @@ -233,7 +233,10 @@ class Connection(BaseConnection): kwargs.pop('password') is_update_password = False else: - encpass = kwargs['password'] if 'password' in kwargs else None + if 'encpass' in kwargs: + encpass = kwargs['encpass'] + else: + encpass = kwargs['password'] if 'password' in kwargs else None return password, encpass, is_update_password