]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Warn for runid changing in load events; add restore_load_context flag
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 31 Jan 2020 16:10:08 +0000 (11:10 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 31 Jan 2020 16:56:21 +0000 (11:56 -0500)
commit10b7937bb9994c365436af5e0c1931b2b07d12b1
treeaa61dd977f43aef0b868938f720fb2243e2cb3ef
parent447dec2c15f7b749a3e98df93c001b1b9a36ed32
Warn for runid changing in load events; add restore_load_context flag

Added a new flag :paramref:`.InstanceEvents.restore_load_context` and
:paramref:`.SessionEvents.restore_load_context` which apply to the
:meth:`.InstanceEvents.load`, :meth:`.InstanceEvents.refresh`, and
:meth:`.SessionEvents.loaded_as_persistent` events, which when set will
restore the "load context" of the object after the event hook has been
called.  This ensures that the object remains within the "loader context"
of the load operation that is already ongoing, rather than the object being
transferred to a new load context due to refresh operations which may have
occurred in the event. A warning is now emitted when this condition occurs,
which recommends use of the flag to resolve this case.  The flag is
"opt-in" so that there is no risk introduced to existing applications.

The change additionally adds support for the ``raw=True`` flag to
session lifecycle events.

Fixes: #5129
Change-Id: I2912f48ac8c5636297d63ed383454930e8e9a6a3
doc/build/changelog/unreleased_13/5129.rst [new file with mode: 0644]
lib/sqlalchemy/orm/events.py
lib/sqlalchemy/orm/loading.py
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/orm/state.py
test/orm/test_events.py