summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-05-25 10:17:11 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-05-25 15:57:03 -0400
commita78718b9340e9840a470300932af178ce57c0f7d (patch)
treed94c45715d4f0dbecdd3be466f52dc5e8c333ac7 /test/sql
parentde11c5217b4c62f86dfd05a28689159095ab1024 (diff)
downloadsqlalchemy-a78718b9340e9840a470300932af178ce57c0f7d.tar.gz
Raise if ForeignKeyConstraint created with different numbers of
local and remote columns. An :class:`.ArgumentError` is now raised if a :class:`.ForeignKeyConstraint` object is created with a mismatched number of "local" and "remote" columns, which otherwise causes the internal state of the constraint to be incorrect. Note that this also impacts the condition where a dialect's reflection process produces a mismatched set of columns for a foreign key constraint. Downstream DB2 dialect has been reported as potentially causing this scenario. Change-Id: Id51c34a6c43749bb582639f9c1dc28723482f0e5 Fixes: #3949 References: #3998
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_metadata.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 6d0df3b5f..61fbbc57b 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -348,6 +348,29 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
getattr, list(a.foreign_keys)[0], "column"
)
+ def test_fk_mismatched_local_remote_cols(self):
+
+ assert_raises_message(
+ exc.ArgumentError,
+ "ForeignKeyConstraint number of constrained columns must "
+ "match the number of referenced columns.",
+ ForeignKeyConstraint, ['a'], ['b.a', 'b.b']
+ )
+
+ assert_raises_message(
+ exc.ArgumentError,
+ "ForeignKeyConstraint number of constrained columns "
+ "must match the number of referenced columns.",
+ ForeignKeyConstraint, ['a', 'b'], ['b.a']
+ )
+
+ assert_raises_message(
+ exc.ArgumentError,
+ "ForeignKeyConstraint with duplicate source column "
+ "references are not supported.",
+ ForeignKeyConstraint, ['a', 'a'], ['b.a', 'b.b']
+ )
+
def test_pickle_metadata_sequence_restated(self):
m1 = MetaData()
Table('a', m1,