From 97f776792fb9e3a3e156bbaadb5c6eb0c853e5e6 Mon Sep 17 00:00:00 2001 From: "Evgeni (Gene) Makarov" Date: Mon, 14 Dec 2020 14:36:21 +0300 Subject: [PATCH 1/2] initializing changes related to string enums for pull request From a8ab206849194c0d1ebfd91abb3a905921bfe5f7 Mon Sep 17 00:00:00 2001 From: "Evgeni (Gene) Makarov" Date: Mon, 14 Dec 2020 14:39:36 +0300 Subject: [PATCH 2/2] 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) -