]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
add "merge" to viewonly cascades; propagate NO_RAISE when merging
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 23 Nov 2022 15:58:28 +0000 (10:58 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 24 Nov 2022 15:15:45 +0000 (10:15 -0500)
commit36914ae33a9d3357c7ad2d219e5af1031891be3c
tree9f7b3ed3edc8afa9ec34c203e46f2900779ea258
parent17313f90e12c30a17048790914f13f8b32c3e86d
add "merge" to viewonly cascades; propagate NO_RAISE when merging

Fixed bug where :meth:`_orm.Session.merge` would fail to preserve the
current loaded contents of relationship attributes that were indicated with
the :paramref:`_orm.relationship.viewonly` parameter, thus defeating
strategies that use :meth:`_orm.Session.merge` to pull fully loaded objects
from caches and other similar techniques. In a related change, fixed issue
where an object that contains a loaded relationship that was nonetheless
configured as ``lazy='raise'`` on the mapping would fail when passed to
:meth:`_orm.Session.merge`; checks for "raise" are now suspended within
the merge process assuming the :paramref:`_orm.Session.merge.load`
parameter remains at its default of ``True``.

Overall, this is a behavioral adjustment to a change introduced in the 1.4
series as of :ticket:`4994`, which took "merge" out of the set of cascades
applied by default to "viewonly" relationships. As "viewonly" relationships
aren't persisted under any circumstances, allowing their contents to
transfer during "merge" does not impact the persistence behavior of the
target object. This allows :meth:`_orm.Session.merge` to correctly suit one
of its use cases, that of adding objects to a :class:`.Session` that were
loaded elsewhere, often for the purposes of restoring from a cache.

Fixes: #8862
Change-Id: I8731c7810460e6a71f8bf5e8ded59142b9b02956
(cherry picked from commit 1e009bf086a42134190030f07068bc463e9a9794)
doc/build/changelog/unreleased_14/8862.rst [new file with mode: 0644]
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/base.py
lib/sqlalchemy/orm/relationships.py
lib/sqlalchemy/orm/util.py
test/orm/test_cascade.py
test/orm/test_merge.py