Skip to content

Commit

Permalink
Raise assertion error if calling .save() on a serializer with errors. C…
Browse files Browse the repository at this point in the history
…loses #2098.
  • Loading branch information
tomchristie committed Dec 2, 2014
1 parent 6ac79b8 commit 79e18a2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def save(self, **kwargs):
(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())
Expand Down

0 comments on commit 79e18a2

Please sign in to comment.