diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-10-02 20:50:56 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-10-03 12:58:38 -0400 |
| commit | 8ba8dd23b7cbf9aa423b6aa965abc4d7174b84de (patch) | |
| tree | 0079f7c2810461dda81f5aaeeb45824283b16d58 /lib/sqlalchemy | |
| parent | b07f8839795adfee40e7d34279242ea1e35dbda8 (diff) | |
| download | sqlalchemy-8ba8dd23b7cbf9aa423b6aa965abc4d7174b84de.tar.gz | |
Improve check for overlapping FK targets on sibling classes
Fixed bug where ORM relationship would warn against conflicting sync
targets (e.g. two relationships would both write to the same column) for
sibling classes in an inheritance hierarchy, where the two relationships
would never actually conflict during writes.
Change-Id: I9367a7978cadc59066e89fc4917d7eb6c78dedee
Fixes: #4078
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/relationships.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 94c0d6694..16e1cdb97 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -1803,6 +1803,15 @@ class RelationshipProperty(StrategizedProperty): (self.key, self.parent.class_) ) + def _persists_for(self, mapper): + """Return True if this property will persist values on behalf + of the given mapper. + + """ + + return self.key in mapper.relationships and \ + mapper.relationships[self.key] is self + def _columns_are_mapped(self, *cols): """Return True if all columns in the given collection are mapped by the tables referenced by this :class:`.Relationship`. @@ -2691,10 +2700,16 @@ class JoinCondition(object): else: other_props = [] prop_to_from = self._track_overlapping_sync_targets[to_] + for pr, fr_ in prop_to_from.items(): if pr.mapper in mapperlib._mapper_registry and \ + ( + self.prop._persists_for(pr.parent) or + pr._persists_for(self.prop.parent) + ) and \ fr_ is not from_ and \ pr not in self.prop._reverse_property: + other_props.append((pr, fr_)) if other_props: |
