Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Support target_session_attrs in URL format, add tests
  • Loading branch information
elprans committed Aug 24, 2023
commit 381cb9df5370bf24ff55f4be0fa72024dda11015
7 changes: 7 additions & 0 deletions asyncpg/connect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
'ssl_max_protocol_version'
)

if 'target_session_attrs' in query:
dsn_target_session_attrs = query.pop(
'target_session_attrs'
)
if target_session_attrs is None:
target_session_attrs = dsn_target_session_attrs

if query:
if server_settings is None:
server_settings = query
Expand Down
36 changes: 36 additions & 0 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,42 @@ class TestConnectParams(tb.TestCase):
})
},

{
'name': 'target_session_attrs',
'dsn': 'postgresql://user@host1:1111,host2:2222/db'
'?target_session_attrs=read-only',
'result': ([('host1', 1111), ('host2', 2222)], {
'database': 'db',
'user': 'user',
'target_session_attrs': 'read-only',
})
},

{
'name': 'target_session_attrs_2',
'dsn': 'postgresql://user@host1:1111,host2:2222/db'
'?target_session_attrs=read-only',
'target_session_attrs': 'read-write',
'result': ([('host1', 1111), ('host2', 2222)], {
'database': 'db',
'user': 'user',
'target_session_attrs': 'read-write',
})
},

{
'name': 'target_session_attrs_3',
'dsn': 'postgresql://user@host1:1111,host2:2222/db',
'env': {
'PGTARGETSESSIONATTRS': 'read-only',
},
'result': ([('host1', 1111), ('host2', 2222)], {
'database': 'db',
'user': 'user',
'target_session_attrs': 'read-only',
})
},

{
'name': 'dsn_ipv6_multi_host',
'dsn': 'postgresql://user@[2001:db8::1234%25eth0],[::1]/db',
Expand Down