From 8ccf87ad042c92288e41561500a842c8409d3e9b Mon Sep 17 00:00:00 2001 From: "Evgeni (Gene) Makarov" Date: Fri, 30 Oct 2020 17:12:25 +0300 Subject: [PATCH] fix for bytes --- src/infi/clickhouse_orm/fields.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/infi/clickhouse_orm/fields.py b/src/infi/clickhouse_orm/fields.py index a17aefc..4f631cc 100644 --- a/src/infi/clickhouse_orm/fields.py +++ b/src/infi/clickhouse_orm/fields.py @@ -473,7 +473,11 @@ class BaseEnumField(Field): 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):