]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
include create_type in pg.ENUM.adapt; test all attrs
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 12 May 2023 18:34:00 +0000 (14:34 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 12 May 2023 19:09:33 +0000 (15:09 -0400)
Fixed apparently very old issue where the
:paramref:`_postgresql.ENUM.create_type` parameter, when set to its
non-default of ``False``, would not be propagated when the
:class:`_schema.Column` which it's a part of were copied, as is common when
using ORM Declarative mixins.

Fixes: #9773
Change-Id: I79a7c6f052ec39b42400d92bf591c791feca573b

doc/build/changelog/unreleased_20/9773.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/named_types.py
lib/sqlalchemy/sql/type_api.py
test/dialect/postgresql/test_types.py

diff --git a/doc/build/changelog/unreleased_20/9773.rst b/doc/build/changelog/unreleased_20/9773.rst
new file mode 100644 (file)
index 0000000..839bfaa
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, postgresql
+    :tickets: 9773
+
+    Fixed apparently very old issue where the
+    :paramref:`_postgresql.ENUM.create_type` parameter, when set to its
+    non-default of ``False``, would not be propagated when the
+    :class:`_schema.Column` which it's a part of were copied, as is common when
+    using ORM Declarative mixins.
index 92aba6f63be6af3e4afdca090a2d419376d133a3..4412d841b783263a05bf995677d93935eef0160f 100644 (file)
@@ -312,6 +312,9 @@ class ENUM(NamedType, sqltypes.NativeForEmulated, sqltypes.Enum):
         kw.setdefault("values_callable", impl.values_callable)
         kw.setdefault("omit_aliases", impl._omit_aliases)
         kw.setdefault("_adapted_from", impl)
+        if type_api._is_native_for_emulated(impl.__class__):
+            kw.setdefault("create_type", impl.create_type)
+
         return cls(**kw)
 
     def create(self, bind=None, checkfirst=True):
index 5af12cb934f100519981fd340e81c494b6afc5d4..312034e9d2f8d49d651581d893be74e4655e170a 100644 (file)
@@ -1482,6 +1482,8 @@ class Emulated(TypeEngineMixin):
                 # as only the default logic is implemented.
                 return cls.adapt_native_to_emulated(self, **kw)
         else:
+            # this would be, both classes are Enum, or both classes
+            # are postgresql.ENUM
             if issubclass(cls, self.__class__):
                 return self.adapt_to_emulated(cls, **kw)
             else:
index f322bf35481b9a1f1f219700661f597b08cab9c2..5df8bc0a5bfe254452ec4ab6a7ec00e7d4f462a4 100644 (file)
@@ -231,6 +231,25 @@ class NamedTypeTest(
         is_(e2.native_enum, True)
         is_(e3.native_enum, True)
 
+    @testing.combinations(
+        ("name", "foobar", "name"),
+        ("validate_strings", True, "validate_strings"),
+        ("omit_aliases", False, "_omit_aliases"),
+        ("create_type", False, "create_type"),
+        ("create_type", True, "create_type"),
+        ("schema", "someschema", "schema"),
+        ("inherit_schema", True, "inherit_schema"),
+        ("metadata", MetaData(), "metadata"),
+        ("values_callable", lambda x: None, "values_callable"),
+    )
+    def test_enum_copy_args(self, argname, value, attrname):
+        kw = {argname: value}
+        e1 = ENUM("a", "b", "c", **kw)
+
+        e1_copy = e1.copy()
+
+        eq_(getattr(e1_copy, attrname), value)
+
     def test_enum_create_table(self, metadata, connection):
         metadata = self.metadata
         t1 = Table(