Bugfix: Fix run validation layer with invalid data

This commit is contained in:
David Medina 2013-05-29 12:47:43 +02:00
parent 85fe7197bf
commit d11b55648c
2 changed files with 15 additions and 1 deletions

View File

@ -315,7 +315,8 @@ class BaseSerializer(WritableField):
self._errors = {}
if data is not None or files is not None:
attrs = self.restore_fields(data, files)
attrs = self.perform_validation(attrs)
if attrs is not None:
attrs = self.perform_validation(attrs)
else:
self._errors['non_field_errors'] = ['No input provided']

View File

@ -63,3 +63,16 @@ class TestPreSaveValidationExclusions(TestCase):
# does not have `blank=True`, so this serializer should not validate.
serializer = ShouldValidateModelSerializer(data={'renamed': ''})
self.assertEqual(serializer.is_valid(), False)
class FieldValidationSerializer(serializers.Serializer):
foo = serializers.CharField()
def validate_foo(self, attrs, source):
raise StandardError("validate_foo was called")
class TestFieldValidationWithInvalidData(TestCase):
def test_validate_foo_was_not_called(self):
serializer = FieldValidationSerializer(data='invalid data')
self.assertFalse(serializer.is_valid())