summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-09-25 10:38:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2018-09-25 10:38:40 -0400
commit0737f45d4ff8fdb2e12972cc58c18345e4d6dde2 (patch)
tree05ce81094cb27d3eeea44af126e34b15ed571228
parentfb991a4474fa0d4df69af10a808fe234016c6a52 (diff)
downloadsqlalchemy-0737f45d4ff8fdb2e12972cc58c18345e4d6dde2.tar.gz
Copy create_constraint flag for Enum
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
-rw-r--r--doc/build/changelog/unreleased_12/4341.rst7
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py2
-rw-r--r--test/sql/test_metadata.py24
3 files changed, 31 insertions, 2 deletions
diff --git a/doc/build/changelog/unreleased_12/4341.rst b/doc/build/changelog/unreleased_12/4341.rst
new file mode 100644
index 000000000..c3db81b20
--- /dev/null
+++ b/doc/build/changelog/unreleased_12/4341.rst
@@ -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.
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py
index 08af78606..e35ed6d1e 100644
--- a/lib/sqlalchemy/sql/sqltypes.py
+++ b/lib/sqlalchemy/sql/sqltypes.py
@@ -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)
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index da133b21a..4976e2fb1 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -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)