From 940d190bc8883328c4c5cde0f43695ad9219290e Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Wed, 12 Jul 2023 10:36:41 +0530 Subject: [PATCH] Fixed an issue where pgAdmin failed to setup role with hyphens in name. #6531 --- docs/en_US/release_notes_7_5.rst | 2 ++ web/pgadmin/utils/driver/psycopg3/connection.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/en_US/release_notes_7_5.rst b/docs/en_US/release_notes_7_5.rst index 8b1455bc9..a51dd9eba 100644 --- a/docs/en_US/release_notes_7_5.rst +++ b/docs/en_US/release_notes_7_5.rst @@ -21,6 +21,7 @@ New features ************ | `Issue #6369 `_ - Added support to detach partitions using concurrently and finalize. + | `Issue #6374 `_ - Added all supported index storage parameters while creating an index. | `Issue #6416 `_ - Added new/missing parameters to pg_dumpall (Backup Server). | `Issue #6417 `_ - Added new/missing parameters to pg_dump (Backup Objects). @@ -47,5 +48,6 @@ Bug fixes | `Issue #6514 `_ - Fix the connection and stability issues since v7, possibly related to background schema changes. | `Issue #6515 `_ - Fixed an issue where the query tool is unable to execute a query on Postgres 10 and below versions. | `Issue #6524 `_ - Fix the lost connection error in v7.4. + | `Issue #6531 `_ - Fixed an issue where pgAdmin failed to setup role with hyphens in name. | `Issue #6537 `_ - Fixed an issue where filters are not working and query history shows empty queries. | `Issue #6544 `_ - Fix an issue where adding a sub-folder inside a folder is not working as expected in File Manager. diff --git a/web/pgadmin/utils/driver/psycopg3/connection.py b/web/pgadmin/utils/driver/psycopg3/connection.py index 697379f9f..3856392c8 100644 --- a/web/pgadmin/utils/driver/psycopg3/connection.py +++ b/web/pgadmin/utils/driver/psycopg3/connection.py @@ -22,7 +22,7 @@ import psycopg from flask import g, current_app from flask_babel import gettext from flask_security import current_user -from pgadmin.utils.crypto import decrypt, encrypt +from pgadmin.utils.crypto import decrypt from psycopg._encodings import py_codecs as encodings import config @@ -39,6 +39,7 @@ from pgadmin.utils import csv from pgadmin.utils.master_password import get_crypt_key from io import StringIO from pgadmin.utils.locker import ConnectionLocker +from pgadmin.utils.driver import get_driver # On Windows, Psycopg is not compatible with the default ProactorEventLoop. @@ -184,6 +185,8 @@ class Connection(BaseConnection): self.reconnecting = False self.use_binary_placeholder = use_binary_placeholder self.array_to_string = array_to_string + self.qtLiteral = get_driver(config.PG_DEFAULT_DRIVER).qtLiteral + super(Connection, self).__init__() def as_dict(self): @@ -442,12 +445,13 @@ class Connection(BaseConnection): role = manager.role if is_set_role: - _query = "SELECT rolname from pg_roles WHERE rolname = '{0}'" \ - "".format(role) + _query = "SELECT rolname from pg_roles WHERE rolname = {0}" \ + "".format(self.qtLiteral(role, self.conn)) _status, res = self.execute_scalar(_query) if res: - status = self._execute(cur, "SET ROLE TO {0}".format(role)) + status = self._execute(cur, "SET ROLE TO {0}".format( + self.qtLiteral(role, self.conn))) else: # If role is not found then set the status to role # for showing the proper error message