]> 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:24:34 +0000 (10:24 +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/_dns.py

index 3155166c1242063b59864eacf2cc24595a390f04..c71a4dcbd2124891a8e1c39d90ad29af503db988 100644 (file)
@@ -7,6 +7,16 @@
 ``psycopg`` release notes
 =========================
 
+Future releases
+---------------
+
+Psycopg 3.0.18
+^^^^^^^^^^^^^^
+
+- Fix possible "unrecognized service" error in async connection when no port
+  is specified (:ticket:`#366`).
+
+
 Current release
 ---------------
 
index f4f1817919bf72f92d1a253dcd3c190a02439c02..9abe7738ee05b298f36d7e7502ae2b42a44f4c36 100644 (file)
@@ -56,7 +56,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 []
 
     if len(ports_in) == 1:
         # If only one port is specified, the libpq will apply it to all