Fixed an issue where pgAdmin failed to setup role with hyphens in name. #6531

This commit is contained in:
Akshay Joshi 2023-07-12 10:36:41 +05:30
parent ab0b1dd40c
commit 940d190bc8
2 changed files with 10 additions and 4 deletions

View File

@ -21,6 +21,7 @@ New features
************
| `Issue #6369 <https://github.com/pgadmin-org/pgadmin4/issues/6369>`_ - Added support to detach partitions using concurrently and finalize.
| `Issue #6374 <https://github.com/pgadmin-org/pgadmin4/issues/6374>`_ - Added all supported index storage parameters while creating an index.
| `Issue #6416 <https://github.com/pgadmin-org/pgadmin4/issues/6416>`_ - Added new/missing parameters to pg_dumpall (Backup Server).
| `Issue #6417 <https://github.com/pgadmin-org/pgadmin4/issues/6417>`_ - Added new/missing parameters to pg_dump (Backup Objects).
@ -47,5 +48,6 @@ Bug fixes
| `Issue #6514 <https://github.com/pgadmin-org/pgadmin4/issues/6514>`_ - Fix the connection and stability issues since v7, possibly related to background schema changes.
| `Issue #6515 <https://github.com/pgadmin-org/pgadmin4/issues/6515>`_ - Fixed an issue where the query tool is unable to execute a query on Postgres 10 and below versions.
| `Issue #6524 <https://github.com/pgadmin-org/pgadmin4/issues/6524>`_ - Fix the lost connection error in v7.4.
| `Issue #6531 <https://github.com/pgadmin-org/pgadmin4/issues/6531>`_ - Fixed an issue where pgAdmin failed to setup role with hyphens in name.
| `Issue #6537 <https://github.com/pgadmin-org/pgadmin4/issues/6537>`_ - Fixed an issue where filters are not working and query history shows empty queries.
| `Issue #6544 <https://github.com/pgadmin-org/pgadmin4/issues/6544>`_ - Fix an issue where adding a sub-folder inside a folder is not working as expected in File Manager.

View File

@ -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