mirror of
https://github.com/enpaul/peewee-plus.git
synced 2024-11-14 18:46:47 +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:
|
def python_value(self, value: str) -> enum.Enum:
|
||||||
try:
|
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:
|
except KeyError:
|
||||||
raise peewee.IntegrityError(
|
raise peewee.IntegrityError(
|
||||||
f"Enum {self.enumeration.__name__} has no value with name '{value}'"
|
f"Enum {self.enumeration.__name__} has no value with name '{value}'"
|
||||||
|
Loading…
Reference in New Issue
Block a user