]> 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 23:14:15 +0000 (01:14 +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 6229bb02d59b930b49301144064b1e0613dca24d..09d4299f027da92568a0d87e744ddbaa9770aef0 100644 (file)
@@ -789,8 +789,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: