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

This commit is contained in:
Tom Christie 2014-12-02 09:27:40 +00:00
parent 6ac79b8223
commit 79e18a2a06

View File

@ -127,6 +127,14 @@ class BaseSerializer(Field):
(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(
list(self.validated_data.items()) +
list(kwargs.items())