]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: remove assert calling informative libpq function
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 7 May 2025 21:40:23 +0000 (23:40 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 7 May 2025 21:42:23 +0000 (23:42 +0200)
At least calling PQport on a connection with multiple attempts ends up
returning a NULL instead of an empty string (libpq from Postgres 17.4).

psycopg/psycopg/pq/pq_ctypes.py
psycopg_c/psycopg_c/pq/pgconn.pyx

index d583960144de3cc860269044372fcde4185209a7..7c16451e3cf1b9796a93f8a84b5f3658ca90ed94 100644 (file)
@@ -790,8 +790,7 @@ class PGconn:
         if not self._pgconn_ptr:
             raise e.OperationalError("the connection is closed")
         rv = func(self._pgconn_ptr)
-        assert rv is not None
-        return rv
+        return rv if rv is not None else b""
 
     def _call_int(self, func: Callable[[impl.PGconn_struct], int]) -> int:
         """
index 7c4eccb832e35d4b48e576f9bc1ea32ad1e03f8e..f8e23d4f3397f5822cfdafffb282c3ebf05ee70e 100644 (file)
@@ -700,8 +700,10 @@ cdef char *_call_bytes(PGconn pgconn, conn_bytes_f func) except NULL:
     if not _ensure_pgconn(pgconn):
         return NULL
     cdef char *rv = func(pgconn._pgconn_ptr)
-    assert rv is not NULL
-    return rv
+    if rv is not NULL:
+        return rv
+    else:
+        return b""
 
 
 cdef int _call_int(PGconn pgconn, conn_int_f func) except -2: