From: Konstantin Lebedev Date: Mon, 20 Feb 2017 16:28:06 +0000 (-0500) Subject: Ensure schema names also compared in foreign_key_constraint() X-Git-Tag: rel_0_9_0~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=93eb6ccbe10133d2c5ff52b8ca2faea81008d72a;p=thirdparty%2Fsqlalchemy%2Falembic.git Ensure schema names also compared in foreign_key_constraint() Fixed bug in :func:`.ops.create_foreign_key` where the internal table representation would not be created properly if the foriegn key referred to a table in a different schema of the same name. Pull request courtesy Konstantin Lebedev. Change-Id: I494c95d02aedbfec3b6318d069322b544cf018fb Pull-request: https://github.com/zzzeek/alembic/pull/36 --- diff --git a/alembic/operations/schemaobj.py b/alembic/operations/schemaobj.py index f0f81057..a01f5be2 100644 --- a/alembic/operations/schemaobj.py +++ b/alembic/operations/schemaobj.py @@ -29,7 +29,7 @@ class SchemaObjects(object): referent_schema=None, initially=None, match=None, **dialect_kw): m = self.metadata() - if source == referent: + if source == referent and source_schema == referent_schema: t1_cols = local_cols + remote_cols else: t1_cols = local_cols diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index 71efc830..01a23a7b 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -7,6 +7,14 @@ Changelog :version: 0.8.11 :released: + .. change:: fk_schema_compare + :tags: bug, operations + + Fixed bug in :func:`.ops.create_foreign_key` where the internal table + representation would not be created properly if the foriegn key referred + to a table in a different schema of the same name. Pull request + courtesy Konstantin Lebedev. + .. changelog:: :version: 0.8.10 :released: January 17, 2017 diff --git a/tests/test_op.py b/tests/test_op.py index a4ada7bd..0c0608a2 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -438,6 +438,16 @@ class OpTest(TestBase): "REFERENCES bar2.t2 (bat, hoho)" ) + def test_add_foreign_key_schema_same_tablename(self): + context = op_fixture() + op.create_foreign_key('fk_test', 't1', 't1', + ['foo', 'bar'], ['bat', 'hoho'], + source_schema='foo2', referent_schema='bar2') + context.assert_( + "ALTER TABLE foo2.t1 ADD CONSTRAINT fk_test FOREIGN KEY(foo, bar) " + "REFERENCES bar2.t1 (bat, hoho)" + ) + def test_add_foreign_key_onupdate(self): context = op_fixture() op.create_foreign_key('fk_test', 't1', 't2',