]> git.ipfire.org Git - thirdparty/psycopg.git/commit
fix: fix possible errors calling __repr__ from __del__.
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 23 Jul 2023 19:33:05 +0000 (20:33 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 23 Jul 2023 19:42:03 +0000 (20:42 +0100)
commit09ee4705acb79c9976e12d276ec298c8829c8926
treead855ce655d08657fb95953f9149b2a3561b7a78
parent5a22fda1793fea34aeca62cc8519b43aa75f2be9
fix: fix possible errors calling __repr__ from __del__.

The errors get ignored but print a warning on program exit and eclipse a
genuine warning.

The error is caused by the `pq.misc` module getting gc'd on interpreter
shutdown before `connection_summary()` is called. The solution is to
import `connection_summary` in the module namespace, which is similar to
the solution that proved working for #198. It is less robust than the
solution used by the Python devs to import the function in the method
via an argument default, but it should work adequately (as nobody
complained about #198 anymore).

In #591 discussion, I proposed that connection_summary is too complex to
be considered safe to call on __del__. Actually, looking at it, it seems
innocent enough, as it only calls objects methods, no functions from
module namespaces. As a consequence we assume that this commit fixes the
issue. As I can't reproduce it, will ask the OP if this is the case.

Close #591.
docs/news.rst
psycopg/psycopg/_pipeline.py
psycopg/psycopg/connection.py
psycopg/psycopg/copy.py
psycopg/psycopg/cursor.py
psycopg/psycopg/transaction.py