]> 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:51:46 +0000 (12:51 -0500)
commit4376c2e5b016e8dfec7bc1b0d2ebbebae737c063
treed16bca4088fada1399e354adc37bef6f0e64d9fd
parent532ddb0fa717bc10c3a95b7ddf3a60bbfad7ac56
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
doc/build/changelog/unreleased_13/5149.rst [new file with mode: 0644]
lib/sqlalchemy/orm/relationships.py
test/orm/test_relationships.py