Loading django/db/models/fields/__init__.py +2 −1 Original line number Diff line number Diff line Loading @@ -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 Loading tests/regressiontests/model_fields/tests.py +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
django/db/models/fields/__init__.py +2 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
tests/regressiontests/model_fields/tests.py +4 −0 Original line number Diff line number Diff line Loading @@ -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