fix(sqlalchemy): safely handle garbage-collected target during event listener removal - #4872
Conversation
|
|
|
This has been sitting without review for ten days, and the test workflows here are still waiting on first-contributor approval — so nothing automated has actually exercised the change yet. I ran it locally, and I think there's a blocker worth catching before a maintainer looks at it.
from sqlalchemy.event import ( # pylint: disable=no-name-in-module
listen,
remove,
)Instrumenting, opening one connection, then calling Same script, same venv, with only So it fires on every Two smaller things while you're in there:
The other half of the change looks right to me — AI-assisted; the traceback and the control run above are output from actually running it, not inferred. |
Fixes #4817
Description
During test teardown or
uninstrument(), event listener cleanup inEngineTracer.remove_all_event_listenerscan fail if the weakref target resolves toNoneor raisesInvalidRequestErrorwhen SQLAlchemy tries to unregister the event.Changes
Nonebefore removal.InvalidRequestErrorduringevent.remove()to prevent flaky teardown crashes.