]> 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:02:44 +0000 (13:02 +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 f01a0d2310d3bcfd0106f9482dc20d00d8779c76..a2c86dc40710ab9a987b9d4bffbcb62c8f25cac9 100644 (file)
@@ -56,8 +56,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 c96dd3b265f8f26015e96b30fdf655652f90425e..513e2f9f48450fb073b9baffb7ddc1d9f27c3ecf 100644 (file)
@@ -661,8 +661,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(