mirror of
				https://github.com/enpaul/peewee-plus.git
				synced 2025-11-04 01:08:38 +00:00 
			
		
		
		
	Ensure NULL-able Enums don't raise peewee.IntegrityError
This commit is contained in:
		@@ -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}'"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user