mirror of
https://github.com/enpaul/peewee-plus.git
synced 2024-12-22 15:53:29 +00:00
Ensure NULL-able Enums don't raise peewee.IntegrityError
This commit is contained in:
parent
44ad5da339
commit
dac554e8d4
@ -367,7 +367,11 @@ class EnumField(peewee.CharField): # pylint: disable=abstract-method
|
||||
|
||||
def python_value(self, value: str) -> enum.Enum:
|
||||
try:
|
||||
return self.enumeration[super().python_value(value)]
|
||||
return (
|
||||
None
|
||||
if value is None and self.null
|
||||
else self.enumeration[super().python_value(value)]
|
||||
)
|
||||
except KeyError:
|
||||
raise peewee.IntegrityError(
|
||||
f"Enum {self.enumeration.__name__} has no value with name '{value}'"
|
||||
|
Loading…
Reference in New Issue
Block a user