Merge pull request #160 from Infinidat/revert-157-case_sensitive_strenums

Revert "Uppercase and lowercase string enums behaviour updated."
This commit is contained in:
Alexander Goldberg 2020-12-07 19:06:16 +02:00 committed by GitHub
commit 779f4146e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -468,16 +468,9 @@ class BaseEnumField(Field):
return value return value
try: try:
if isinstance(value, str): if isinstance(value, str):
try:
return self.enum_cls[value] return self.enum_cls[value]
except Exception:
return self.enum_cls(value)
if isinstance(value, bytes): if isinstance(value, bytes):
decoded = value.decode('UTF-8') return self.enum_cls[value.decode('UTF-8')]
try:
return self.enum_cls[decoded]
except Exception:
return self.enum_cls(decoded)
if isinstance(value, int): if isinstance(value, int):
return self.enum_cls(value) return self.enum_cls(value)
except (KeyError, ValueError): except (KeyError, ValueError):
@ -672,3 +665,4 @@ class LowCardinalityField(Field):
# Expose only relevant classes in import * # Expose only relevant classes in import *
__all__ = get_subclass_names(locals(), Field) __all__ = get_subclass_names(locals(), Field)