CHECK constraints assocaited w/ Boolean, Enum get doubled on tometadata()

Issue #3260 resolved
Mike Bayer repo owner created an issue
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 3f24fd0..74044e3 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -1473,6 +1473,46 @@ class SchemaTypeTest(fixtures.TestBase):

         m1.create_all(testing.db)

+    def test_boolean_constraint_type_doesnt_double(self):
+        m1 = MetaData()
+
+        t1 = Table('x', m1, Column("flag", Boolean()))
+        eq_(
+            len([
+                c for c in t1.constraints
+                if isinstance(c, CheckConstraint)]),
+            1
+        )
+        m2 = MetaData()
+        t2 = t1.tometadata(m2)
+
+        eq_(
+            len([
+                c for c in t2.constraints
+                if isinstance(c, CheckConstraint)]),
+            1
+        )
+
+    def test_enum_constraint_type_doesnt_double(self):
+        m1 = MetaData()
+
+        t1 = Table('x', m1, Column("flag", Enum('a', 'b', 'c')))
+        eq_(
+            len([
+                c for c in t1.constraints
+                if isinstance(c, CheckConstraint)]),
+            1
+        )
+        m2 = MetaData()
+        t2 = t1.tometadata(m2)
+
+        eq_(
+            len([
+                c for c in t2.constraints
+                if isinstance(c, CheckConstraint)]),
+            1
+        )
+

Comments (1)

  1. Mike Bayer reporter
    • Fixed bug in :meth:.Table.tometadata method where the :class:.CheckConstraint associated with a :class:.Boolean or :class:.Enum type object would be doubled in the target table. The copy process now tracks the production of this constraint object as local to a type object. fixes #3260

    → <<cset 98c2a6797074>>

  2. Log in to comment