]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add length to enum repr params
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Mar 2022 22:30:21 +0000 (17:30 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Mar 2022 22:30:21 +0000 (17:30 -0500)
This amends the fix for #7789.

Fixes: #7598
Change-Id: I067a081d743f1efaf8288601bec0400712012265

doc/build/changelog/unreleased_14/7720_7789.rst
lib/sqlalchemy/sql/sqltypes.py
test/sql/test_types.py

index 5c1026ef5f61dc15698cd16dc0abcf96e3740861..5a521fe0103a25de8a3cef9be2169f58607dcb9c 100644 (file)
@@ -1,6 +1,6 @@
 .. change::
     :tags: bug, sql, mysql
-    :tickets: 7720, 7789
+    :tickets: 7720, 7789, 7598
 
     Fixed issues in :class:`_mysql.SET` datatype as well as :class:`.Enum`
     where the ``__repr__()`` method would not render all optional parameters in
index 3794fd8f793c80e7363456280f83336528a47237..6b2d3654b5e237bb857563a485b2e876108c8af2 100644 (file)
@@ -1321,9 +1321,9 @@ class Enum(Emulated, String, TypeEngine[Union[str, enum.Enum]], SchemaType):
         self.validate_strings = kw.pop("validate_strings", False)
 
         if self.enums:
-            length = max(len(x) for x in self.enums)
+            self._default_length = length = max(len(x) for x in self.enums)
         else:
-            length = 0
+            self._default_length = length = 0
         if not self.native_enum and length_arg is not NO_ARG:
             if length_arg < length:
                 raise ValueError(
@@ -1456,6 +1456,7 @@ class Enum(Emulated, String, TypeEngine[Union[str, enum.Enum]], SchemaType):
             additional_kw=[
                 ("native_enum", True),
                 ("create_constraint", False),
+                ("length", self._default_length),
             ],
             to_inspect=[Enum, SchemaType],
         )
index 58dfa4dd8aee64cab367cad201ba2794f36530c3..d7b9ae6550ee1c340e329973a3bc45f508efac89 100644 (file)
@@ -2486,6 +2486,13 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
             "Enum('x', 'y', name='somename', create_constraint=True)",
         )
 
+    def test_repr_three(self):
+        e = Enum("x", "y", native_enum=False, length=255)
+        eq_(
+            repr(e),
+            "Enum('x', 'y', native_enum=False, length=255)",
+        )
+
     def test_length_native(self):
         e = Enum("x", "y", "long", length=42)