]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: use a "finally" to clear the result pointer after handling notifies
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 27 Aug 2022 20:29:56 +0000 (21:29 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 28 Aug 2022 12:01:21 +0000 (13:01 +0100)
The chance for this to fail failed is slim (an error in the logger? A
ctrl-c just there?) but a bit of paranoia has never hurt anyone.

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

index 48fd53f0d60a591cccb179049679719df7dbef4f..6096d0c039642e43f1121b24c34180a5e5953cc3 100644 (file)
@@ -55,8 +55,8 @@ def notice_receiver(arg: c_void_p, result_ptr: impl.PGresult_struct) -> None:
         pgconn.notice_handler(res)
     except Exception as exc:
         logger.exception("error in notice receiver: %s", exc)
-
-    res._pgresult_ptr = None  # avoid destroying the pgresult_ptr
+    finally:
+        res._pgresult_ptr = None  # avoid destroying the pgresult_ptr
 
 
 class PGconn:
index 07e4fc5072b14898cd6d101e716a403f7fbc3519..44270743204835c0af3221f36ee9d9c6447d1d30 100644 (file)
@@ -644,8 +644,8 @@ cdef void notice_receiver(void *arg, const libpq.PGresult *res_ptr) with gil:
         pgconn.notice_handler(res)
     except Exception as e:
         logger.exception("error in notice receiver: %s", e)
-
-    res._pgresult_ptr = NULL  # avoid destroying the pgresult_ptr
+    finally:
+        res._pgresult_ptr = NULL  # avoid destroying the pgresult_ptr
 
 
 cdef (Py_ssize_t, libpq.Oid *, char * const*, int *, int *) _query_params_args(