From: Daniele Varrazzo Date: Wed, 7 May 2025 21:40:23 +0000 (+0200) Subject: fix: remove assert calling informative libpq function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40dfa0b;p=thirdparty%2Fpsycopg.git fix: remove assert calling informative libpq function 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). --- diff --git a/psycopg/psycopg/pq/pq_ctypes.py b/psycopg/psycopg/pq/pq_ctypes.py index d58396014..7c16451e3 100644 --- a/psycopg/psycopg/pq/pq_ctypes.py +++ b/psycopg/psycopg/pq/pq_ctypes.py @@ -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: """ diff --git a/psycopg_c/psycopg_c/pq/pgconn.pyx b/psycopg_c/psycopg_c/pq/pgconn.pyx index 7c4eccb83..f8e23d4f3 100644 --- a/psycopg_c/psycopg_c/pq/pgconn.pyx +++ b/psycopg_c/psycopg_c/pq/pgconn.pyx @@ -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: