From: Mike Bayer Date: Thu, 24 May 2012 14:58:43 +0000 (-0400) Subject: - identify another condition, indirectly via #2491, where X-Git-Tag: rel_0_8_0b1~411 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=33986147a3aff8f10976aabbe860ce3dae8e8ca3;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - identify another condition, indirectly via #2491, where remote/local detection was regressing vs. 0.7. use a more liberal check for "tables overlap". --- diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 9b828ee047..55c5071df1 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -16,7 +16,7 @@ and `secondaryjoin` aspects of :func:`.relationship`. from sqlalchemy import sql, util, log, exc as sa_exc, schema from sqlalchemy.sql.util import ClauseAdapter, criterion_as_pairs, \ join_condition, _shallow_annotate, visit_binary_product,\ - _deep_deannotate + _deep_deannotate, find_tables from sqlalchemy.sql import operators, expression, visitors from sqlalchemy.orm.interfaces import MANYTOMANY, MANYTOONE, ONETOMANY @@ -418,10 +418,11 @@ class JoinCondition(object): def _tables_overlap(self): """Return True if parent/child tables have some overlap.""" - return self.parent_selectable.is_derived_from( - self.child_local_selectable) or \ - self.child_selectable.is_derived_from( - self.parent_local_selectable) + return bool( + set(find_tables(self.parent_selectable)).intersection( + find_tables(self.child_selectable) + ) + ) def _annotate_remote(self): """Annotate the primaryjoin and secondaryjoin diff --git a/test/orm/test_rel_fn.py b/test/orm/test_rel_fn.py index c00a903fa9..3f43762be6 100644 --- a/test/orm/test_rel_fn.py +++ b/test/orm/test_rel_fn.py @@ -288,6 +288,20 @@ class _JoinFixtures(object): primaryjoin=self.sub_w_base_rel.c.base_id==self.base.c.id ) + def _join_fixture_m2o_joined_sub_to_sub_on_base(self, **kw): + # this is a late add - a variant of the test case + # in #2491 where we join on the base cols instead. only + # m2o has a problem at the time of this test. + left = self.base.join(self.sub, self.base.c.id==self.sub.c.id) + right = self.base.join(self.sub_w_base_rel, self.base.c.id==self.sub_w_base_rel.c.id) + return relationships.JoinCondition( + left, + right, + self.sub, + self.sub_w_base_rel, + primaryjoin=self.sub_w_base_rel.c.base_id==self.base.c.id, + ) + def _join_fixture_o2m_joined_sub_to_sub(self, **kw): left = self.base.join(self.sub, self.base.c.id==self.sub.c.id) right = self.base.join(self.sub_w_sub_rel, self.base.c.id==self.sub_w_sub_rel.c.id) @@ -473,6 +487,13 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL [(self.left.c.id, self.right.c.lid)] ) + def test_determinelocal_remote_m2o_joined_sub_to_sub_on_base(self): + joincond = self._join_fixture_m2o_joined_sub_to_sub_on_base() + eq_( + joincond.local_remote_pairs, + [(self.base.c.id, self.sub_w_base_rel.c.base_id)] + ) + def test_determine_local_remote_base_to_joined_sub(self): joincond = self._join_fixture_base_to_joined_sub() eq_( @@ -501,17 +522,6 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL ) def test_determine_remote_columns_o2m_joined_sub_to_sub(self): - def _join_fixture_o2m_joined_sub_to_sub(self, **kw): - left = self.base.join(self.sub, self.base.c.id==self.sub.c.id) - right = self.base.join(self.sub_w_sub_rel, self.base.c.id==self.sub_w_sub_rel.c.id) - return relationships.JoinCondition( - left, - right, - self.sub, - self.sub_w_sub_rel, - primaryjoin=self.sub.c.id==self.sub_w_sub_rel.c.sub_id - ) - joincond = self._join_fixture_o2m_joined_sub_to_sub() eq_( joincond.local_remote_pairs,