]> 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:30 +0000 (11:56 -0500)
commit93a7de2ef8abc843e857b0a3bb61e8ca64ad1234
tree91ec812a93aff8ee919c2b3905d48252cdf371b1
parent906ee6b01fa8a6048d0cf2d9bdb73016e1b26741
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
(cherry picked from commit 10b7937bb9994c365436af5e0c1931b2b07d12b1)
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