Commit ad237fb7 authored by Brendan MacDonell's avatar Brendan MacDonell Committed by Claude Paroz
Browse files

Fixed #18724 -- Fixed IntegerField validation with value 0

parent 9a3026a9
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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)