Skip to content

Commit 8c5c1bf

Browse files
committed
Fix DSN parsing regression
1d650ed broke certain cases of DSN parsing, fix that.
1 parent e8120c5 commit 8c5c1bf

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

asyncpg/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
# snapshots will automatically include the git revision
3232
# in __version__, for example: '0.16.0.dev0+ge06ad03'
3333

34-
__version__ = '0.18.0'
34+
__version__ = '0.18.1'

asyncpg/connect_utils.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
215215
else:
216216
hostspec = parsed.netloc
217217

218-
host, port = _parse_hostlist(hostspec, port)
218+
if hostspec:
219+
host, port = _parse_hostlist(hostspec, port)
219220

220221
if parsed.path and database is None:
221222
database = parsed.path
@@ -234,16 +235,16 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
234235
if isinstance(val, list):
235236
query[key] = val[-1]
236237

237-
if 'host' in query:
238-
val = query.pop('host')
239-
if not host and val:
240-
host, port = _parse_hostlist(val, port)
241-
242238
if 'port' in query:
243239
val = query.pop('port')
244240
if not port and val:
245241
port = [int(p) for p in val.split(',')]
246242

243+
if 'host' in query:
244+
val = query.pop('host')
245+
if not host and val:
246+
host, port = _parse_hostlist(val, port)
247+
247248
if 'dbname' in query:
248249
val = query.pop('dbname')
249250
if database is None:

tests/test_connect.py

+10
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@ class TestConnectParams(tb.TestCase):
392392
'could not match 2 port numbers to 3 hosts'
393393
)
394394
},
395+
{
396+
'dsn': 'postgres://user@?port=56226&host=%2Ftmp',
397+
'result': (
398+
[os.path.join('/tmp', '.s.PGSQL.56226')],
399+
{
400+
'user': 'user',
401+
'database': 'user',
402+
}
403+
)
404+
},
395405
]
396406

397407
@contextlib.contextmanager

0 commit comments

Comments
 (0)