]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: make sure to pass a port number to getaddrinfo
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 2 Sep 2022 15:30:23 +0000 (16:30 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 4 Sep 2022 09:20:21 +0000 (10:20 +0100)
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.

docs/news.rst
psycopg/psycopg/conninfo.py
tests/test_conninfo.py

index d6705af4a7973afd4b7e4f3448ac192b7f6df171..86cfc758cf59bc851233c13b9e1d4a5b77a73447 100644 (file)
@@ -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
 ---------------
 
index 273b78a2c90a7b4b75d34c8c7bcf597f5d5b6376..331a1f958f65d5c9351c766457f20e79550d52a5 100644 (file)
@@ -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:
index 296ec0604b08cb20db6755ba8c7f3429da62f41a..da5c5dbc0ea252932836e78f9501dfe076878e8d 100644 (file)
@@ -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: