From 9fd4d188708ff4d5a11dde806acda6792b810703 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Wed, 7 Apr 2021 22:02:10 +0200 Subject: Unify native and non-native valid values for ``Enum`` Unify behaviour :class:`_schema.Enum` in native and non-native implementations regarding the accepted values for an enum with aliased elements. When :paramref:`_schema.Enum.omit_aliases` is ``False`` all values, alias included, are accepted as valid values. When :paramref:`_schema.Enum.omit_aliases` is ``True`` only non aliased values are accepted as valid values. Fixes: #6146 Change-Id: I6f40789c1ca56e533990882deadcc6a377d4fc40 --- lib/sqlalchemy/sql/sqltypes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index e57a14681..fd3118e30 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -1692,7 +1692,7 @@ class Enum(Emulated, String, SchemaType): variant_mapping = self._variant_mapping_for_set_table(column) e = schema.CheckConstraint( - type_coerce(column, self).in_(self.enums), + type_coerce(column, String()).in_(self.enums), name=_NONE_NAME if self.name is None else self.name, _create_rule=util.portable_instancemethod( self._should_create_constraint, @@ -1714,13 +1714,14 @@ class Enum(Emulated, String, SchemaType): return process def bind_processor(self, dialect): + parent_processor = super(Enum, self).bind_processor(dialect) + def process(value): value = self._db_value_for_elem(value) if parent_processor: value = parent_processor(value) return value - parent_processor = super(Enum, self).bind_processor(dialect) return process def result_processor(self, dialect, coltype): -- cgit v1.2.1