.. changelog::
:version: 1.1.3
+ .. change::
+ :tags: bug, sql
+ :tickets: 3833
+
+ Fixed bug involving new value translation and validation feature
+ in :class:`.Enum` whereby using the enum object in a string
+ concatenation would maintain the :class:`.Enum` type as the type
+ of the expression overall, producing missing lookups. A string
+ concatenation against an :class:`.Enum`-typed column now uses
+ :class:`.String` as the datatype of the expression itself.
+
.. change::
:tags: bug, sql
:tickets: 3832
raise LookupError(
'"%s" is not among the defined enum values' % elem)
+ class Comparator(String.Comparator):
+
+ def _adapt_expression(self, op, other_comparator):
+ op, typ = super(Enum.Comparator, self)._adapt_expression(
+ op, other_comparator)
+ if op is operators.concat_op:
+ typ = String(
+ self.type.length,
+ convert_unicode=self.type.convert_unicode)
+ return op, typ
+
+ comparator_factory = Comparator
+
def _object_value_for_elem(self, elem):
try:
return self._object_lookup[elem]
]
)
+ def test_validators_not_in_concatenate_roundtrip(self):
+ enum_table = self.tables['non_native_enum_table']
+
+ enum_table.insert().execute([
+ {'id': 1, 'someenum': 'two'},
+ {'id': 2, 'someenum': 'two'},
+ {'id': 3, 'someenum': 'one'},
+ ])
+
+ eq_(
+ select(['foo' + enum_table.c.someenum]).
+ order_by(enum_table.c.id).execute().fetchall(),
+ [
+ ('footwo', ),
+ ('footwo', ),
+ ('fooone', )
+ ]
+ )
+
@testing.fails_on(
'postgresql+zxjdbc',
'zxjdbc fails on ENUM: column "XXX" is of type XXX '