From a8ab206849194c0d1ebfd91abb3a905921bfe5f7 Mon Sep 17 00:00:00 2001 From: "Evgeni (Gene) Makarov" Date: Mon, 14 Dec 2020 14:39:36 +0300 Subject: [PATCH] changes reverted after rebase --- src/infi/clickhouse_orm/fields.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/infi/clickhouse_orm/fields.py b/src/infi/clickhouse_orm/fields.py index b63997e..4f631cc 100644 --- a/src/infi/clickhouse_orm/fields.py +++ b/src/infi/clickhouse_orm/fields.py @@ -468,9 +468,16 @@ class BaseEnumField(Field): return value try: if isinstance(value, str): - return self.enum_cls[value] + try: + return self.enum_cls[value] + except Exception: + return self.enum_cls(value) if isinstance(value, bytes): - return self.enum_cls[value.decode('UTF-8')] + decoded = value.decode('UTF-8') + try: + return self.enum_cls[decoded] + except Exception: + return self.enum_cls(decoded) if isinstance(value, int): return self.enum_cls(value) except (KeyError, ValueError): @@ -665,4 +672,3 @@ class LowCardinalityField(Field): # Expose only relevant classes in import * __all__ = get_subclass_names(locals(), Field) -