From: Mike Bayer Date: Fri, 4 Mar 2022 22:30:21 +0000 (-0500) Subject: add length to enum repr params X-Git-Tag: rel_1_4_32~5^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8c293145f2aa6d9bf90fd717ec45d947171f15c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add length to enum repr params This amends the fix for #7789. Fixes: #7598 Change-Id: I067a081d743f1efaf8288601bec0400712012265 (cherry picked from commit a26a522648af14ffb9388d8d306bd98523bef1c9) --- diff --git a/doc/build/changelog/unreleased_14/7720_7789.rst b/doc/build/changelog/unreleased_14/7720_7789.rst index 5c1026ef5f..5a521fe010 100644 --- a/doc/build/changelog/unreleased_14/7720_7789.rst +++ b/doc/build/changelog/unreleased_14/7720_7789.rst @@ -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 diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 726313fcf4..cc3dbffc5d 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -1520,9 +1520,9 @@ class Enum(Emulated, String, SchemaType): _expect_unicode = convert_unicode 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( @@ -1675,6 +1675,7 @@ class Enum(Emulated, String, SchemaType): additional_kw=[ ("native_enum", True), ("create_constraint", False), + ("length", self._default_length), ], to_inspect=[Enum, SchemaType], ) diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 8530b90433..9f8b8a662c 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -2514,6 +2514,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)