Commit 79e18a2a by Tom Christie

Raise assertion error if calling .save() on a serializer with errors. Closes #2098.

parent 6ac79b82
...@@ -127,6 +127,14 @@ class BaseSerializer(Field): ...@@ -127,6 +127,14 @@ class BaseSerializer(Field):
(self.__class__.__module__, self.__class__.__name__) (self.__class__.__module__, self.__class__.__name__)
) )
assert hasattr(self, '_errors'), (
'You must call `.is_valid()` before calling `.save()`.'
)
assert not self.errors, (
'You cannot call `.save()` on a serializer with invalid data.'
)
validated_data = dict( validated_data = dict(
list(self.validated_data.items()) + list(self.validated_data.items()) +
list(kwargs.items()) list(kwargs.items())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment