MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _set_imap_in_disposal

Method _set_imap_in_disposal

test/orm/test_session.py:2423–2443  ·  view source on GitHub ↗

remove selected objects from the given session, as though they were dereferenced and removed from WeakIdentityMap. Hardcodes the identity map's "all_states()" method to return the full list of states. This simulates the all_states() method returning results, afterwh

(self, sess, *objs)

Source from the content-addressed store, hash-verified

2421 _sessions.clear()
2422
2423 def _set_imap_in_disposal(self, sess, *objs):
2424 """remove selected objects from the given session, as though
2425 they were dereferenced and removed from WeakIdentityMap.
2426
2427 Hardcodes the identity map's "all_states()" method to return the
2428 full list of states. This simulates the all_states() method
2429 returning results, afterwhich some of the states get garbage
2430 collected (this normally only happens during asynchronous gc).
2431 The Session now has one or more InstanceState's which have been
2432 removed from the identity map and disposed.
2433
2434 Will the Session not trip over this ??? Stay tuned.
2435
2436 """
2437
2438 all_states = sess.identity_map.all_states()
2439 sess.identity_map.all_states = lambda: all_states
2440 for obj in objs:
2441 state = attributes.instance_state(obj)
2442 sess.identity_map.discard(state)
2443 state._dispose()
2444
2445 def _test_session(self, **kwargs):
2446 T = self.classes.T

Callers 1

_test_sessionMethod · 0.95

Calls 3

_disposeMethod · 0.80
all_statesMethod · 0.45
discardMethod · 0.45

Tested by

no test coverage detected