diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-09-11 11:51:44 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-09-11 11:51:44 -0400 |
commit | f98c89d2bee2ae562c79d91aeb96fd55875db917 (patch) | |
tree | 32587780d07551d6d092c8740acecdb700042002 | |
parent | 14d2bb074cccdec32bd26a89353c30fd512b2aa2 (diff) | |
download | sqlalchemy-f98c89d2bee2ae562c79d91aeb96fd55875db917.tar.gz |
- Fixed warning that would emit when a complex self-referential
primaryjoin contained functions, while at the same time remote_side
was specified; the warning would suggest setting "remote side".
It now only emits if remote_side isn't present.
fixes #3194
-rw-r--r-- | doc/build/changelog/changelog_09.rst | 12 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/relationships.py | 8 | ||||
-rw-r--r-- | test/orm/test_rel_fn.py | 20 |
3 files changed, 35 insertions, 5 deletions
diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index accd827f8..329e054b0 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,8 +14,18 @@ :version: 0.9.8 .. change:: + :tags: bug, orm + :versions: 1.0.0 + :tickets: 3194 + + Fixed warning that would emit when a complex self-referential + primaryjoin contained functions, while at the same time remote_side + was specified; the warning would suggest setting "remote side". + It now only emits if remote_side isn't present. + + .. change:: :tags: bug, ext - :verions: 1.0.0 + :versions: 1.0.0 :tickets: 3191 Fixed bug in ordering list where the order of items would be diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 95ff21444..56a33742d 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -2181,7 +2181,7 @@ class JoinCondition(object): elif self._local_remote_pairs or self._remote_side: self._annotate_remote_from_args() elif self._refers_to_parent_table(): - self._annotate_selfref(lambda col: "foreign" in col._annotations) + self._annotate_selfref(lambda col: "foreign" in col._annotations, False) elif self._tables_overlap(): self._annotate_remote_with_overlap() else: @@ -2200,7 +2200,7 @@ class JoinCondition(object): self.secondaryjoin = visitors.replacement_traverse( self.secondaryjoin, {}, repl) - def _annotate_selfref(self, fn): + def _annotate_selfref(self, fn, remote_side_given): """annotate 'remote' in primaryjoin, secondaryjoin when the relationship is detected as self-referential. @@ -2215,7 +2215,7 @@ class JoinCondition(object): if fn(binary.right) and not equated: binary.right = binary.right._annotate( {"remote": True}) - else: + elif not remote_side_given: self._warn_non_column_elements() self.primaryjoin = visitors.cloned_traverse( @@ -2240,7 +2240,7 @@ class JoinCondition(object): remote_side = self._remote_side if self._refers_to_parent_table(): - self._annotate_selfref(lambda col: col in remote_side) + self._annotate_selfref(lambda col: col in remote_side, True) else: def repl(element): if element in remote_side: diff --git a/test/orm/test_rel_fn.py b/test/orm/test_rel_fn.py index f0aa538f4..150b59b75 100644 --- a/test/orm/test_rel_fn.py +++ b/test/orm/test_rel_fn.py @@ -242,6 +242,22 @@ class _JoinFixtures(object): **kw ) + def _join_fixture_o2m_composite_selfref_func_remote_side(self, **kw): + return relationships.JoinCondition( + self.composite_selfref, + self.composite_selfref, + self.composite_selfref, + self.composite_selfref, + primaryjoin=and_( + self.composite_selfref.c.group_id == + func.foo(self.composite_selfref.c.group_id), + self.composite_selfref.c.parent_id == + self.composite_selfref.c.id + ), + remote_side=set([self.composite_selfref.c.parent_id]), + **kw + ) + def _join_fixture_o2m_composite_selfref_func_annotated(self, **kw): return relationships.JoinCondition( self.composite_selfref, @@ -729,6 +745,10 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, self._join_fixture_o2m_composite_selfref_func ) + def test_determine_local_remote_pairs_o2m_composite_selfref_func_rs(self): + # no warning + self._join_fixture_o2m_composite_selfref_func_remote_side() + def test_determine_local_remote_pairs_o2m_overlap_func_warning(self): self._assert_non_simple_warning( self._join_fixture_m2o_sub_to_joined_sub_func |