]> 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 16:50:48 +0000 (11:50 -0500)
commitdf3bd8d29740e846d7faac842a6e2de16cf483f0
tree32ebad081b7279839b2e26fde79a4e010ea2f2fc
parentfbec926c4744aa97a48a011939354c8b8f8be566
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
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