From: Mike Bayer Date: Fri, 28 Mar 2014 20:41:08 +0000 (-0400) Subject: - add further coverage for join_condition to make sure we get this case where X-Git-Tag: rel_0_9_4~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c731b2ebf4909d319bf7ce44c4c5e895723afa6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add further coverage for join_condition to make sure we get this case where there are multiple, equivalent foreign keys --- diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index ce48d4c4b4..f64a70ec8d 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -740,7 +740,7 @@ class Join(FromClause): if len(constraints) > 1: dedupe = set(tuple(crit) for crit in constraints.values()) if len(dedupe) == 1: - key = constraints.keys()[0] + key = list(constraints)[0] constraints = {key: constraints[key]} if len(constraints) != 1: diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 5d3d53b888..a5693acd3b 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -1062,6 +1062,16 @@ class JoinConditionTest(fixtures.TestBase, AssertsCompiledSQL): "FROM t2 JOIN t3 ON t2.id = t3.t2id) ON t2.id = t3_t2id") + def test_join_multiple_equiv_fks(self): + m = MetaData() + t1 = Table('t1', m, + Column('id', Integer, primary_key=True) + ) + t2 = Table('t2', m, + Column('t1id', Integer, ForeignKey('t1.id'), ForeignKey('t1.id')) + ) + + assert sql_util.join_condition(t1, t2).compare(t1.c.id == t2.c.t1id) def test_join_cond_no_such_unrelated_table(self): m = MetaData()