diff --git a/web/pgadmin/utils/driver/psycopg3/connection.py b/web/pgadmin/utils/driver/psycopg3/connection.py index 47ab25b7660..35d3984d50c 100644 --- a/web/pgadmin/utils/driver/psycopg3/connection.py +++ b/web/pgadmin/utils/driver/psycopg3/connection.py @@ -17,7 +17,6 @@ import secrets import datetime import asyncio -import copy from collections import deque import psycopg from flask import g, current_app @@ -281,7 +280,6 @@ def connect(self, **kwargs): password, encpass, is_update_password = \ self._check_user_password(kwargs) - passfile = kwargs['passfile'] if 'passfile' in kwargs else None tunnel_password = kwargs['tunnel_password'] if 'tunnel_password' in \ kwargs else '' @@ -313,14 +311,28 @@ def connect(self, **kwargs): if is_error: return False, errmsg - # If no password credential is found then connect request might - # come from Query tool, ViewData grid, debugger etc tools. - # we will check for pgpass file availability from connection manager - # if it's present then we will use it - if not password and not encpass and not passfile: - passfile = manager.get_connection_param_value('passfile') - if manager.passexec: + # If no password credential is found then connect request might come + # from Query tool, ViewData grid, debugger, etc. In that case, fall + # back to using the password returned from manager.passexec. + passfile = manager.get_connection_param_value('passfile') + if not password and not encpass and manager.passexec: + if not passfile: password = manager.passexec.get() + else: + current_app.logger.warning( + 'Ignoring passexec in favor of the specified passfile ' + f'({passfile!r}).' + ) + + # create_connection_string() automatically picks up the passfile from + # connection parameters. Warn if that differs from the passfile kwarg. + passfile_kwarg = kwargs.get('passfile', None) + if passfile_kwarg and passfile_kwarg != passfile: + current_app.logger.warning( + 'Conflicting passfiles specified through keyword arguments ' + f'({passfile_kwarg!r}) and connection parameters ' + f'({passfile!r}); using the latter.' + ) try: database = self.db