mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Bugfix: Fix run validation layer with invalid data
This commit is contained in:
parent
85fe7197bf
commit
d11b55648c
|
@ -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']
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue
Block a user