summaryrefslogtreecommitdiff
path: root/test/sql/test_selectable.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-09-15 00:50:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-09-15 00:54:15 -0400
commit25804aeae262fa01256dbd2f045ad4a380644f66 (patch)
tree9016ee540e1b1ca9d4b4c6e20f9d6517e37047df /test/sql/test_selectable.py
parent6e1f34ed6230d7fce338ee4fb022678a7e511627 (diff)
downloadsqlalchemy-25804aeae262fa01256dbd2f045ad4a380644f66.tar.gz
Repair foreign_keys population for Join._refresh_for_new_column
Fixed bug where setting up a single-table inh subclass of a joined-table subclass which included an extra column would corrupt the foreign keys collection of the mapped table, thereby interfering with the initialization of relationships. Change-Id: I04a0cf98fd456d12d5a5b9e77a46a01246969a63 Fixes: #3797
Diffstat (limited to 'test/sql/test_selectable.py')
-rw-r--r--test/sql/test_selectable.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py
index 94e4ac024..95a0336b7 100644
--- a/test/sql/test_selectable.py
+++ b/test/sql/test_selectable.py
@@ -916,6 +916,44 @@ class RefreshForNewColTest(fixtures.TestBase):
j._refresh_for_new_column(q)
assert j.c.b_q is q
+ def test_fk_table(self):
+ m = MetaData()
+ fk = ForeignKey('x.id')
+ Table('x', m, Column('id', Integer))
+ a = Table('a', m, Column('x', Integer, fk))
+ a.c
+
+ q = Column('q', Integer)
+ a.append_column(q)
+ a._refresh_for_new_column(q)
+ eq_(a.foreign_keys, set([fk]))
+
+ fk2 = ForeignKey('g.id')
+ p = Column('p', Integer, fk2)
+ a.append_column(p)
+ a._refresh_for_new_column(p)
+ eq_(a.foreign_keys, set([fk, fk2]))
+
+ def test_fk_join(self):
+ m = MetaData()
+ fk = ForeignKey('x.id')
+ Table('x', m, Column('id', Integer))
+ a = Table('a', m, Column('x', Integer, fk))
+ b = Table('b', m, Column('y', Integer))
+ j = a.join(b, a.c.x == b.c.y)
+ j.c
+
+ q = Column('q', Integer)
+ b.append_column(q)
+ j._refresh_for_new_column(q)
+ eq_(j.foreign_keys, set([fk]))
+
+ fk2 = ForeignKey('g.id')
+ p = Column('p', Integer, fk2)
+ b.append_column(p)
+ j._refresh_for_new_column(p)
+ eq_(j.foreign_keys, set([fk, fk2]))
+
class AnonLabelTest(fixtures.TestBase):