fix: quote username in views/mview test helper for dotted local roles

Same dot-username bug as 504775de8 / 9b29bc203 but in a different shape:
view_test_data.json query strings are Python expressions interpolating
server['username'] into ALTER TABLE ... OWNER TO and GRANT ... TO
clauses. views/tests/utils.py:create_view evaluates these expressions,
producing SQL with an unquoted identifier. A local PG role with a dot
(e.g. 'ashesh.vashi') was rejected with 'syntax error at or near "."'.

Substitute server['username'] with Driver.qtIdent(None, server['username'])
in the query template before evaluating, so the resulting SQL contains
the properly-quoted identifier. The substitution covers every
occurrence in the template (some queries have OWNER TO and GRANT TO in
the same string).

Accounts for the remaining 72 'syntax error at or near "."' cases that
504775de8 + 9b29bc203 did not reach.
This commit is contained in:
Ashesh Vashi committed 2026-05-01 23:09:09 +05:30
1 parent 9b29bc2033
commit dc61039e93
1 file changed
+11
@@ -13,6 +13,7 @@ import traceback
import os
import json
from pgadmin.utils.driver.psycopg3 import Driver
from regression.python_test_utils import test_utils as utils
from urllib.parse import urlencode
@@ -179,6 +180,16 @@ def create_view(server, db_name, schema_name, view_name, sql_query=None,
old_isolation_level = connection.isolation_level
utils.set_isolation_level(connection, 0)
pg_cursor = connection.cursor()
# Quote server['username'] as an SQL identifier inside the query
# template, so usernames containing special characters (e.g. dots
# like 'ashesh.vashi') do not parse as schema-qualified names.
# view_test_data.json query strings interpolate server['username']
# directly into ALTER TABLE ... OWNER TO and GRANT ... TO clauses
# where the identifier must be quoted.
sql_query = sql_query.replace(
"server['username']",
"Driver.qtIdent(None, server['username'])"
)
query = eval(sql_query)
pg_cursor.execute(query)
utils.set_isolation_level(connection, old_isolation_level)