Skip to content

Commit f5654bd

Browse files
author
egalpin
committed
Adds multiple host handling via DSN parsing
1 parent 45f0e2a commit f5654bd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

asyncpg/connect_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
6464
port = int(parsed.port)
6565

6666
if parsed.hostname and host is None:
67-
host = parsed.hostname
67+
host = parsed.hostname.split(',')
6868

6969
if parsed.path and database is None:
7070
database = parsed.path

tests/test_connect.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ class TestConnectParams(tb.TestCase):
316316
'dsn': 'pq:///dbname?host=/unix_sock/test&user=spam',
317317
'error': (ValueError, 'invalid DSN')
318318
},
319+
320+
{
321+
'dsn': 'postgres://user3:123123@localhost,127.0.0.1:5555/abcdef',
322+
'result': ([('localhost', 5555), ('127.0.0.1', 5555)], {
323+
'user': 'user3',
324+
'password': '123123',
325+
'database': 'abcdef'})
326+
},
319327
]
320328

321329
@contextlib.contextmanager

0 commit comments

Comments
 (0)