summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-06-10 18:19:06 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-06-10 18:19:06 +0000
commitb163099ada4009b2bdc9538c04120aee1f13dcc8 (patch)
tree04bf4250c50c60ea20a5eb4b0ac968a0d88c301d /lib/sqlalchemy/sql
parent6bbc1ef1e9cdb38b3697b42272355b164f0f0242 (diff)
parent4274981156a554fb4b8340d2fa4d8c4afed7c86c (diff)
downloadsqlalchemy-b163099ada4009b2bdc9538c04120aee1f13dcc8.tar.gz
Merge "honor enum length in all cases" into main
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py33
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py
index 2cc46107b..faa0c794c 100644
--- a/lib/sqlalchemy/sql/sqltypes.py
+++ b/lib/sqlalchemy/sql/sqltypes.py
@@ -1322,10 +1322,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),
@@ -1425,22 +1429,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