From: Daniele Varrazzo Date: Mon, 28 Dec 2020 03:38:28 +0000 (+0100) Subject: Added guard to avoid failure on __del__ of unborn connection X-Git-Tag: 3.0.dev0~229 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ccf23858efbac7c3a55a63508f4349a1986faaa;p=thirdparty%2Fpsycopg.git Added guard to avoid failure on __del__ of unborn connection --- diff --git a/psycopg3/psycopg3/connection.py b/psycopg3/psycopg3/connection.py index 059212332..f3e4b35da 100644 --- a/psycopg3/psycopg3/connection.py +++ b/psycopg3/psycopg3/connection.py @@ -124,6 +124,10 @@ class BaseConnection(AdaptContext): pgconn.notify_handler = partial(BaseConnection._notify_handler, wself) def __del__(self) -> None: + # If fails on connection we might not have this attribute yet + if not hasattr(self, "pgconn"): + return + status = self.pgconn.transaction_status if status == TransactionStatus.UNKNOWN: return