mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Fixed bug in ChoiceField, when it makes possible to submit 0 as value, when it is not in choices
Since we check just for bool(value) and bool(0) is False, it doesn't perform validation even when required=True. required=True logic checks value for existing in django core EMPTY_VALUES list, but 0 is not in it, which is logical. But in validate of ChoiseField, we should do "if value is provided and it is not empty(None, [], {}), perform validation". Tom, it is critical, please, take a look :(
This commit is contained in:
parent
b3af4d9fe7
commit
fbb74e7a40
|
@ -552,7 +552,7 @@ class ChoiceField(WritableField):
|
|||
Validates that the input is in self.choices.
|
||||
"""
|
||||
super(ChoiceField, self).validate(value)
|
||||
if value and not self.valid_value(value):
|
||||
if value not in validators.EMPTY_VALUES and not self.valid_value(value):
|
||||
raise ValidationError(self.error_messages['invalid_choice'] % {'value': value})
|
||||
|
||||
def valid_value(self, value):
|
||||
|
|
Loading…
Reference in New Issue
Block a user