From: Daniele Varrazzo Date: Fri, 2 Sep 2022 15:30:23 +0000 (+0100) Subject: fix: make sure to pass a port number to getaddrinfo X-Git-Tag: 3.1.1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a395f70c7e291e482a2a341d039341b036b936c8;p=thirdparty%2Fpsycopg.git fix: make sure to pass a port number to getaddrinfo Was passing an empty string by mistake, if no port was specified. Mostly not a problem, except on some platforms, where it causes an "unrecognized service" error. Close #366. --- diff --git a/docs/news.rst b/docs/news.rst index d6705af4a..86cfc758c 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -7,6 +7,16 @@ ``psycopg`` release notes ========================= +Future releases +--------------- + +Psycopg 3.1.1 +^^^^^^^^^^^^^ + +- Fix possible "unrecognized service" error in async connection when no port + is specified (:ticket:`#366`). + + Current release --------------- diff --git a/psycopg/psycopg/conninfo.py b/psycopg/psycopg/conninfo.py index 273b78a2c..331a1f958 100644 --- a/psycopg/psycopg/conninfo.py +++ b/psycopg/psycopg/conninfo.py @@ -304,7 +304,7 @@ async def resolve_hostaddr_async(params: Dict[str, Any]) -> Dict[str, Any]: hosts_in = host_arg.split(",") port_arg: str = str(params.get("port", os.environ.get("PGPORT", ""))) - ports_in = port_arg.split(",") + ports_in = port_arg.split(",") if port_arg else [] default_port = "5432" if len(ports_in) == 1: diff --git a/tests/test_conninfo.py b/tests/test_conninfo.py index 296ec0604..da5c5dbc0 100644 --- a/tests/test_conninfo.py +++ b/tests/test_conninfo.py @@ -432,6 +432,7 @@ async def fake_resolve(monkeypatch): } async def fake_getaddrinfo(host, port, **kwargs): + assert isinstance(port, int) or (isinstance(port, str) and port.isdigit()) try: addr = fake_hosts[host] except KeyError: