[Sqlalchemy-tickets] Issue #3808: persistent_to_deleted does not accommodate for garbage collected
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2016-09-30 01:38:38
|
New issue 3808: persistent_to_deleted does not accommodate for garbage collected object https://bitbucket.org/zzzeek/sqlalchemy/issues/3808/persistent_to_deleted-does-not-accommodate Michael Bayer: ``` #!diff diff --git a/test/orm/test_events.py b/test/orm/test_events.py index ab61077..0a11c12 100644 --- a/test/orm/test_events.py +++ b/test/orm/test_events.py @@ -1872,6 +1872,31 @@ class SessionLifecycleEventsTest(_RemoveListeners, _fixtures.FixtureTest): ] ) + def test_persistent_to_deleted_del(self): + sess, User, start_events = self._fixture() + + u1 = User(name='u1') + sess.add(u1) + sess.flush() + + listener = start_events() + + @event.listens_for(sess, "persistent_to_deleted") + def persistent_to_deleted(session, instance): + assert instance is not None + + sess.delete(u1) + del u1 + + sess.flush() + + eq_( + listener.mock_calls, + [ + call.persistent_to_deleted(sess, None), # should we send state here? + ] + ) + def test_detached_to_persistent_via_cascaded_delete(self): sess, User, Address, start_events = self._fixture(include_address=True) ``` this is critical for 1.1 because the API is broken. either we don't call the event or we send the state (And should we change the signature so that we know if state is there or not? propose send both object and state). fails because the object is gone. the event signature here is broken, we can't always send the object along. there might be some other events that have this also, the object would have to be persistent first and not be subject to strong_ref. persistent_to_transient for example seems to have a strong ref. |