summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2020-02-17 21:01:44 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2020-02-17 21:01:44 +0000
commit236db97fc419722d51236097d9bba1e645c4c7db (patch)
tree2c3f2f372eef666a5dc5a13634f15033aa574cc8 /lib/sqlalchemy
parent386012597b9e7aa2a7f987930d00b892ed54121d (diff)
parent4376c2e5b016e8dfec7bc1b0d2ebbebae737c063 (diff)
downloadsqlalchemy-236db97fc419722d51236097d9bba1e645c4c7db.tar.gz
Merge "Begin to disallow back_populates with viewonly=True"
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/relationships.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py
index d745500c1..5573f7c9a 100644
--- a/lib/sqlalchemy/orm/relationships.py
+++ b/lib/sqlalchemy/orm/relationships.py
@@ -827,6 +827,19 @@ class RelationshipProperty(StrategizedProperty):
the full set of related objects, to prevent modifications of the
collection from resulting in persistence operations.
+ .. warning:: The viewonly=True relationship should not be mutated
+ in Python; that means, elements should not be added or removed
+ from collections nor should a many-to-one or one-to-one attribute
+ be altered in Python. The viewonly=True relationship should only
+ be accessed via read. Towards this behavior, it is also not
+ appropriate for the viewonly=True relationship to have any kind
+ of persistence cascade settings, nor should it be the target of
+ either :paramref:`.relationship.backref` or
+ :paramref:`.relationship.back_populates`, as backrefs imply
+ in-Python mutation of the attribute. SQLAlchemy may emit
+ warnings for some or all of these conditions as of the 1.3 and
+ 1.4 series of SQLAlchemy and will eventually be disallowed.
+
:param omit_join:
Allows manual control over the "selectin" automatic join
optimization. Set to ``False`` to disable the "omit join" feature
@@ -1841,6 +1854,14 @@ class RelationshipProperty(StrategizedProperty):
def _add_reverse_property(self, key):
other = self.mapper.get_property(key, _configure_mappers=False)
+ if other.viewonly:
+ util.warn_limited(
+ "Setting backref / back_populates on relationship %s to refer "
+ "to viewonly relationship %s will be deprecated in SQLAlchemy "
+ "1.4, and will be disallowed in a future release. "
+ "viewonly relationships should not be mutated",
+ (self, other),
+ )
self._reverse_property.add(other)
other._reverse_property.add(self)