]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Copy create_constraint flag for Enum
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 25 Sep 2018 14:38:40 +0000 (10:38 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 25 Sep 2018 14:38:40 +0000 (10:38 -0400)
Fixed bug where the :paramref:`.Enum.create_constraint` flag on  the
:class:`.Enum` datatype would not be propagated to copies of the type, which
affects use cases such as declarative mixins and abstract bases.

Fixes: #4341
Change-Id: I978be65f33a616fe4d5f5de03fb3eaab6f6a2272

doc/build/changelog/unreleased_12/4341.rst [new file with mode: 0644]
lib/sqlalchemy/sql/sqltypes.py
test/sql/test_metadata.py

diff --git a/doc/build/changelog/unreleased_12/4341.rst b/doc/build/changelog/unreleased_12/4341.rst
new file mode 100644 (file)
index 0000000..c3db81b
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+   :tags: bug, sql
+   :tickets: 4341
+
+   Fixed bug where the :paramref:`.Enum.create_constraint` flag on  the
+   :class:`.Enum` datatype would not be propagated to copies of the type, which
+   affects use cases such as declarative mixins and abstract bases.
index 08af78606a5acaca6a6b8cf96a132e71c662a42e..e35ed6d1e15c89afcb2a94bf5273ef49a9c27345 100644 (file)
@@ -1057,7 +1057,6 @@ class SchemaType(SchemaEventTarget):
         schema = kw.pop('schema', self.schema)
         metadata = kw.pop('metadata', self.metadata)
         _create_events = kw.pop('_create_events', False)
-
         return impltype(name=self.name,
                         schema=schema,
                         inherit_schema=self.inherit_schema,
@@ -1442,6 +1441,7 @@ class Enum(Emulated, String, SchemaType):
         kw.setdefault('_create_events', False)
         kw.setdefault('native_enum', self.native_enum)
         kw.setdefault('values_callable', self.values_callable)
+        kw.setdefault('create_constraint', self.create_constraint)
         assert '_enums' in kw
         return impltype(**kw)
 
index da133b21ab6c1de17157eaf6f3a80400ed7c2091..4976e2fb1064f4fcdbeaec75ccfc152bcb23b529 100644 (file)
@@ -15,7 +15,7 @@ import sqlalchemy as tsa
 from sqlalchemy.testing import fixtures
 from sqlalchemy import testing
 from sqlalchemy.testing import ComparesTables, AssertsCompiledSQL
-from sqlalchemy.testing import eq_, is_, mock, is_true
+from sqlalchemy.testing import eq_, is_, mock, is_true, is_false
 from contextlib import contextmanager
 from sqlalchemy import util
 from sqlalchemy.testing import engines
@@ -1879,6 +1879,18 @@ class SchemaTypeTest(fixtures.TestBase):
         m.dispatch.before_create(t1, testing.db)
         eq_(t1.c.y.type.evt_targets, (t1, ))
 
+    def test_enum_nonnative_column_copy_transfers_constraintpref(self):
+        m = MetaData()
+
+        type_ = self.WrapEnum(
+            'a', 'b', 'c', name='foo',
+            native_enum=False, create_constraint=False)
+        y = Column('y', type_)
+        y_copy = y.copy()
+        Table('x', m, y_copy)
+
+        is_false(y_copy.type.create_constraint)
+
     def test_boolean_column_copy_transfers_events(self):
         m = MetaData()
 
@@ -1889,6 +1901,16 @@ class SchemaTypeTest(fixtures.TestBase):
 
         is_true(y_copy.type._create_events)
 
+    def test_boolean_nonnative_column_copy_transfers_constraintpref(self):
+        m = MetaData()
+
+        type_ = self.WrapBoolean(create_constraint=False)
+        y = Column('y', type_)
+        y_copy = y.copy()
+        Table('x', m, y_copy)
+
+        is_false(y_copy.type.create_constraint)
+
     def test_metadata_dispatch_no_new_impl(self):
         m1 = MetaData()
         typ = self.MyType(metadata=m1)