return
if "foreign" not in binary.left._annotations and \
- "foreign" not in binary.right._annotations:
+ "foreign" not in binary.right._annotations:
col = is_foreign(binary.left, binary.right)
if col is not None:
if col.compare(binary.left):
def visit_binary(binary):
equated = binary.left.compare(binary.right)
if isinstance(binary.left, expression.ColumnClause) and \
- isinstance(binary.right, expression.ColumnClause):
+ isinstance(binary.right, expression.ColumnClause):
# assume one to many - FKs are "remote"
if fn(binary.left):
binary.left = binary.left._annotate({"remote": True})
- if fn(binary.right) and \
- not equated:
+ if fn(binary.right) and not equated:
binary.right = binary.right._annotate(
{"remote": True})
else:
def proc_left_right(left, right):
if isinstance(left, expression.ColumnClause) and \
- isinstance(right, expression.ColumnClause):
+ isinstance(right, expression.ColumnClause):
if self.child_selectable.c.contains_column(right) and \
- self.parent_selectable.c.contains_column(left):
+ self.parent_selectable.c.contains_column(left):
right = right._annotate({"remote": True})
else:
self._warn_non_column_elements()
not self.parent_local_selectable.c.\
contains_column(element)
or self.child_local_selectable.c.\
- contains_column(element)
- ):
+ contains_column(element)):
return element._annotate({"remote": True})
self.primaryjoin = visitors.replacement_traverse(
self.primaryjoin, {}, repl)
def locals_(elem):
if "remote" not in elem._annotations and \
- elem in local_side:
+ elem in local_side:
return elem._annotate({"local": True})
self.primaryjoin = visitors.replacement_traverse(
self.primaryjoin, {}, locals_
can_sync = bool(self.secondary_synchronize_pairs)
if self.support_sync and can_sync or \
- (not self.support_sync and has_foreign):
+ (not self.support_sync and has_foreign):
return
# from here below is just determining the best error message
"Ensure that only those columns referring "
"to a parent column are marked as foreign, "
"either via the foreign() annotation or "
- "via the foreign_keys argument."
- % self.prop)
+ "via the foreign_keys argument." % self.prop)
elif onetomany_fk:
self.direction = ONETOMANY
elif manytoone_fk:
def visit_binary(binary, left, right):
if "remote" in right._annotations and \
"remote" not in left._annotations and \
- self.can_be_synced_fn(left):
+ self.can_be_synced_fn(left):
lrp.add((left, right))
elif "remote" in left._annotations and \
"remote" not in right._annotations and \
- self.can_be_synced_fn(right):
+ self.can_be_synced_fn(right):
lrp.add((right, left))
if binary.operator is operators.eq and \
- self.can_be_synced_fn(left, right):
+ self.can_be_synced_fn(left, right):
if "foreign" in right._annotations:
collection.append((left, right))
elif "foreign" in left._annotations:
-from sqlalchemy.testing import assert_raises, assert_raises_message, eq_, \
+from sqlalchemy.testing import assert_raises_message, eq_, \
AssertsCompiledSQL, is_
from sqlalchemy.testing import fixtures
from sqlalchemy.orm import relationships, foreign, remote
support_sync=False,
can_be_synced_fn=_can_sync,
primaryjoin=and_(
- self.three_tab_a.c.id==self.three_tab_b.c.aid,
- self.three_tab_c.c.bid==self.three_tab_b.c.id,
- self.three_tab_c.c.aid==self.three_tab_a.c.id
+ self.three_tab_a.c.id == self.three_tab_b.c.aid,
+ self.three_tab_c.c.bid == self.three_tab_b.c.id,
+ self.three_tab_c.c.aid == self.three_tab_a.c.id
)
)
self.composite_selfref,
self.composite_selfref,
primaryjoin=and_(
- self.composite_selfref.c.group_id==
+ self.composite_selfref.c.group_id ==
func.foo(self.composite_selfref.c.group_id),
- self.composite_selfref.c.parent_id==
+ self.composite_selfref.c.parent_id ==
self.composite_selfref.c.id
),
**kw
self.composite_selfref,
self.composite_selfref,
primaryjoin=and_(
- remote(self.composite_selfref.c.group_id)==
+ remote(self.composite_selfref.c.group_id) ==
func.foo(self.composite_selfref.c.group_id),
- remote(self.composite_selfref.c.parent_id)==
+ remote(self.composite_selfref.c.parent_id) ==
self.composite_selfref.c.id
),
**kw
# see test/orm/inheritance/test_abc_inheritance:TestaTobM2O
# and others there
right = self.base_w_sub_rel.join(self.rel_sub,
- self.base_w_sub_rel.c.id==self.rel_sub.c.id
+ self.base_w_sub_rel.c.id == self.rel_sub.c.id
)
return relationships.JoinCondition(
self.base_w_sub_rel,
right,
self.base_w_sub_rel,
self.rel_sub,
- primaryjoin=self.base_w_sub_rel.c.sub_id==\
+ primaryjoin=self.base_w_sub_rel.c.sub_id == \
self.rel_sub.c.id,
**kw
)
def _join_fixture_o2m_joined_sub_to_base(self, **kw):
left = self.base.join(self.sub_w_base_rel,
- self.base.c.id==self.sub_w_base_rel.c.id)
+ self.base.c.id == self.sub_w_base_rel.c.id)
return relationships.JoinCondition(
left,
self.base,
self.sub_w_base_rel,
self.base,
- primaryjoin=self.sub_w_base_rel.c.base_id==self.base.c.id
+ 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)
+ 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,
+ 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)
+ 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
+ primaryjoin=self.sub.c.id == self.sub_w_sub_rel.c.sub_id
)
def _join_fixture_m2o_sub_to_joined_sub(self, **kw):
# see test.orm.test_mapper:MapperTest.test_add_column_prop_deannotate,
right = self.base.join(self.right_w_base_rel,
- self.base.c.id==self.right_w_base_rel.c.id)
+ self.base.c.id == self.right_w_base_rel.c.id)
return relationships.JoinCondition(
self.right_w_base_rel,
right,
def _join_fixture_m2o_sub_to_joined_sub_func(self, **kw):
# see test.orm.test_mapper:MapperTest.test_add_column_prop_deannotate,
right = self.base.join(self.right_w_base_rel,
- self.base.c.id==self.right_w_base_rel.c.id)
+ self.base.c.id == self.right_w_base_rel.c.id)
return relationships.JoinCondition(
self.right_w_base_rel,
right,
self.right_w_base_rel,
self.right_w_base_rel,
- primaryjoin=self.right_w_base_rel.c.base_id==\
+ primaryjoin=self.right_w_base_rel.c.base_id == \
func.foo(self.base.c.id)
)
def _join_fixture_o2o_joined_sub_to_base(self, **kw):
left = self.base.join(self.sub,
- self.base.c.id==self.sub.c.id)
+ self.base.c.id == self.sub.c.id)
# see test_relationships->AmbiguousJoinInterpretedAsSelfRef
return relationships.JoinCondition(
self.right,
self.left,
self.right,
- primaryjoin=self.left.c.id==
+ primaryjoin=self.left.c.id ==
foreign(func.foo(self.right.c.lid)),
**kw
)
self.right,
self.left,
self.right,
- primaryjoin=self.left.c.id==
+ primaryjoin=self.left.c.id ==
func.foo(self.right.c.lid),
consider_as_foreign_keys=[self.right.c.lid],
**kw
)
def _assert_raises_no_relevant_fks(self, fn, expr, relname,
- primary, *arg, **kw):
+ primary, *arg, **kw):
assert_raises_message(
exc.ArgumentError,
r"Could not locate any relevant foreign key columns "
)
def _assert_raises_no_equality(self, fn, expr, relname,
- primary, *arg, **kw):
+ primary, *arg, **kw):
assert_raises_message(
- sa.exc.ArgumentError,
+ exc.ArgumentError,
"Could not locate any simple equality expressions "
"involving locally mapped foreign key columns for %s join "
"condition '%s' on relationship %s. "
)
def _assert_raises_ambig_join(self, fn, relname, secondary_arg,
- *arg, **kw):
+ *arg, **kw):
if secondary_arg is not None:
assert_raises_message(
exc.AmbiguousForeignKeysError,
fn, *arg, **kw)
def _assert_raises_no_join(self, fn, relname, secondary_arg,
- *arg, **kw):
+ *arg, **kw):
if secondary_arg is not None:
assert_raises_message(
exc.NoForeignKeysError,
"parent/child tables on relationship %s - "
"there are no foreign keys linking these tables "
"via secondary table '%s'. "
- "Ensure that referencing columns are associated with a ForeignKey "
+ "Ensure that referencing columns are associated "
+ "with a ForeignKey "
"or ForeignKeyConstraint, or specify 'primaryjoin' and "
"'secondaryjoin' expressions"
% (relname, secondary_arg),
"Could not determine join condition between "
"parent/child tables on relationship %s - "
"there are no foreign keys linking these tables. "
- "Ensure that referencing columns are associated with a ForeignKey "
+ "Ensure that referencing columns are associated "
+ "with a ForeignKey "
"or ForeignKeyConstraint, or specify a 'primaryjoin' "
"expression."
% (relname,),
fn, *arg, **kw)
-class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL):
+class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase,
+ AssertsCompiledSQL):
def test_determine_local_remote_pairs_o2o_joined_sub_to_base(self):
joincond = self._join_fixture_o2o_joined_sub_to_base()
eq_(
]
)
- def test_determine_local_remote_compound_1(self):
+ def test_determine_local_remote_compound_3(self):
joincond = self._join_fixture_compound_expression_1()
eq_(
joincond.local_remote_pairs,
eq_(
joincond.local_remote_pairs,
[
- (self.composite_selfref.c.group_id, self.composite_selfref.c.group_id),
- (self.composite_selfref.c.id, self.composite_selfref.c.parent_id),
+ (self.composite_selfref.c.group_id,
+ self.composite_selfref.c.group_id),
+ (self.composite_selfref.c.id,
+ self.composite_selfref.c.parent_id),
]
)
eq_(
joincond.local_remote_pairs,
[
- (self.composite_selfref.c.group_id, self.composite_selfref.c.group_id),
- (self.composite_selfref.c.id, self.composite_selfref.c.parent_id),
+ (self.composite_selfref.c.group_id,
+ self.composite_selfref.c.group_id),
+ (self.composite_selfref.c.id,
+ self.composite_selfref.c.parent_id),
]
)
eq_(
j2.local_remote_pairs,
[
- (self.m2mright.c.id, self.m2msecondary.c.rid),
- (self.m2mleft.c.id, self.m2msecondary.c.lid),
+ (self.m2mright.c.id, self.m2msecondary.c.rid),
+ (self.m2mleft.c.id, self.m2msecondary.c.lid),
]
)