]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Begin to disallow back_populates with viewonly=True
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 11 Feb 2020 17:51:46 +0000 (12:51 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 11 Feb 2020 17:54:27 +0000 (12:54 -0500)
commit6a742e49874e56116c4a667346ff99b0f8da4f65
tree555a3992257df1622bd9d040c9dd935a82a95afb
parente9544a3be13a10659ad2d6fa87a5d6190996b301
Begin to disallow back_populates with viewonly=True

A viewonly=True relationship should not be mutated and ideally
mutation itself would raise an error, but we're not there yet.
Warn when a viewonly is to be the target of a back_populates
as this only means that it should be locally mutated, which
by definition will not work as expected because post-flush
it will deliver doubled results, due to its state not being
reset.

Setting a relationship to viewonly=True which is also the target of a
back_populates or backref configuration will now emit a warning and
eventually be disallowed. back_populates refers specifically to mutation
of an attribute or collection, which is disallowed when the attribute is
subject to viewonly=True.   The viewonly attribute is not subject to
persistence behaviors which means it will not reflect correct results
when it is locally mutated.

Fixes: #5149
Change-Id: Ie51382a82e1a0ff5f3cf2cdbded780e77ace7f5f
(cherry picked from commit 4376c2e5b016e8dfec7bc1b0d2ebbebae737c063)
doc/build/changelog/unreleased_13/5149.rst [new file with mode: 0644]
lib/sqlalchemy/orm/relationships.py
test/orm/test_relationships.py