Skip to content

Commit 1d92c31

Browse files
committed
fix(python-driver): Python 3.9-safe hints and correct $user in search_path
- Use Optional[str] for configure_connection graph_name (PEP 604 unions are invalid on Python 3.9). - Import Any/Optional from typing for annotations. - Quote $user in SET search_path; align unit test expectations. Made-with: Cursor
1 parent 53ae0fe commit 1d92c31

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

drivers/python/age/age.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# under the License.
1515

1616
import re
17+
from typing import Any, Optional
18+
1719
import psycopg
1820
from psycopg.types import TypeInfo
1921
from psycopg import sql
@@ -144,7 +146,7 @@ def setUpAge(conn:psycopg.connection, graphName:str, load_from_plugins:bool=Fals
144146
else:
145147
cursor.execute("LOAD 'age';")
146148

147-
cursor.execute("SET search_path = ag_catalog, '$user', public;")
149+
cursor.execute('SET search_path = ag_catalog, "$user", public;')
148150

149151
ag_info = TypeInfo.fetch(conn, 'agtype')
150152

@@ -165,7 +167,7 @@ def setUpAge(conn:psycopg.connection, graphName:str, load_from_plugins:bool=Fals
165167

166168
def configure_connection(
167169
conn: psycopg.connection,
168-
graph_name: str | None = None,
170+
graph_name: Optional[str] = None,
169171
load: bool = False,
170172
load_from_plugins: bool = False,
171173
) -> None:
@@ -209,7 +211,7 @@ def configure_connection(
209211
else:
210212
cursor.execute("LOAD 'age';")
211213

212-
cursor.execute("SET search_path = ag_catalog, '$user', public;")
214+
cursor.execute('SET search_path = ag_catalog, "$user", public;')
213215

214216
ag_info = TypeInfo.fetch(conn, 'agtype')
215217

drivers/python/test_age_py.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_default_does_not_load(self):
122122
unittest.mock.patch("age.age.checkGraphCreated"):
123123
age.age.configure_connection(mock_conn)
124124
mock_cursor.execute.assert_called_once_with(
125-
"SET search_path = ag_catalog, '$user', public;"
125+
'SET search_path = ag_catalog, "$user", public;'
126126
)
127127

128128
def test_load_true_executes_load(self):
@@ -154,7 +154,7 @@ def test_always_sets_search_path(self):
154154
unittest.mock.patch("age.age.checkGraphCreated"):
155155
age.age.configure_connection(mock_conn)
156156
mock_cursor.execute.assert_any_call(
157-
"SET search_path = ag_catalog, '$user', public;"
157+
'SET search_path = ag_catalog, "$user", public;'
158158
)
159159

160160
def test_registers_agtype_adapters(self):

0 commit comments

Comments
 (0)