diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-06-10 12:42:54 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-06-10 13:21:26 -0400 |
commit | 4274981156a554fb4b8340d2fa4d8c4afed7c86c (patch) | |
tree | 5c20a6f9102f2a75e6d5c799e0ec9ec3ba9e784c /lib/sqlalchemy/sql | |
parent | b171f5d2e488c46a664847644e65d5dc03759840 (diff) | |
download | sqlalchemy-4274981156a554fb4b8340d2fa4d8c4afed7c86c.tar.gz |
honor enum length in all cases
The :paramref:`.Enum.length` parameter, which sets the length of the
``VARCHAR`` column for non-native enumeration types, is now used
unconditionally when emitting DDL for the ``VARCHAR`` datatype, including
when the :paramref:`.Enum.native_enum` parameter is set to ``True`` for
target backends that continue to use ``VARCHAR``. Previously the parameter
would be erroneously ignored in this case. The warning previously emitted
for this case is now removed.
Fixes: #7791
Change-Id: I91764546b56e9416479949be8a118cdc91ac5ed9
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r-- | lib/sqlalchemy/sql/sqltypes.py | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 50cb32503..7b18fda72 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -1316,10 +1316,14 @@ class Enum(String, SchemaType, Emulated, TypeEngine[Union[str, enum.Enum]]): ignored if native_enum=True. :param length: Allows specifying a custom length for the VARCHAR - when :paramref:`.Enum.native_enum` is False. By default it uses the - length of the longest value. + when a non-native enumeration datatype is used. By default it uses + the length of the longest value. + + .. versionchanged:: 2.0.0 The :paramref:`.Enum.length` parameter + is used unconditionally for ``VARCHAR`` rendering regardless of + the :paramref:`.Enum.native_enum` parameter, for those backends + where ``VARCHAR`` is used for enumerated datatypes. - .. versionadded:: 1.3.16 :param schema: Schema name of this type. For types that exist on the target database as an independent schema construct (PostgreSQL), @@ -1419,22 +1423,13 @@ class Enum(String, SchemaType, Emulated, TypeEngine[Union[str, enum.Enum]]): self._default_length = length = 0 if length_arg is not NO_ARG: - if self.native_enum: - if not _disable_warnings: - util.warn( - "Enum 'length' argument is currently ignored unless " - "native_enum is specified as False, including for DDL " - "that renders VARCHAR in any case. This may change " - "in a future release." - ) - else: - if not _disable_warnings and length_arg < length: - raise ValueError( - "When provided, length must be larger or equal" - " than the length of the longest enum value. %s < %s" - % (length_arg, length) - ) - length = length_arg + if not _disable_warnings and length_arg < length: + raise ValueError( + "When provided, length must be larger or equal" + " than the length of the longest enum value. %s < %s" + % (length_arg, length) + ) + length = length_arg self._valid_lookup[None] = self._object_lookup[None] = None |