mirror of
https://github.com/django/django.git
synced 2024-12-24 10:05:46 +00:00
Fixed #18724 -- Fixed IntegerField validation with value 0
This commit is contained in:
parent
9a3026a920
commit
ad237fb72f
@ -179,7 +179,8 @@ class Field(object):
|
||||
if not self.editable:
|
||||
# Skip validation for non-editable fields.
|
||||
return
|
||||
if self._choices and value:
|
||||
|
||||
if self._choices and value not in validators.EMPTY_VALUES:
|
||||
for option_key, option_value in self.choices:
|
||||
if isinstance(option_value, (list, tuple)):
|
||||
# This is an optgroup, so look inside the group for
|
||||
|
@ -274,6 +274,10 @@ class ValidationTest(test.TestCase):
|
||||
self.assertRaises(ValidationError, f.clean, None, None)
|
||||
self.assertRaises(ValidationError, f.clean, '', None)
|
||||
|
||||
def test_integerfield_validates_zero_against_choices(self):
|
||||
f = models.IntegerField(choices=((1, 1),))
|
||||
self.assertRaises(ValidationError, f.clean, '0', None)
|
||||
|
||||
def test_charfield_raises_error_on_empty_input(self):
|
||||
f = models.CharField(null=False)
|
||||
self.assertRaises(ValidationError, f.clean, None, None)
|
||||
|
Loading…
Reference in New Issue
Block a user