Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support target_session_attrs in URL format, add tests #1073

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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