fix for bytes

This commit is contained in:
Evgeni (Gene) Makarov 2020-10-30 17:12:25 +03:00
parent c4ab81ebe1
commit 8ccf87ad04

View File

@ -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):