diff options
| author | Tom Christie | 2014-12-02 09:27:40 +0000 |
|---|---|---|
| committer | Tom Christie | 2014-12-02 09:27:40 +0000 |
| commit | 79e18a2a06178e8c00dfafc1cfd062f2528ec2c1 (patch) | |
| tree | cc2dbbe9bf0031183a8ace9f93888198bdb5b9e8 | |
| parent | 6ac79b822325784ad145ff0ad064127750c4f7e0 (diff) | |
| download | django-rest-framework-79e18a2a06178e8c00dfafc1cfd062f2528ec2c1.tar.bz2 | |
Raise assertion error if calling .save() on a serializer with errors. Closes #2098.
| -rw-r--r-- | rest_framework/serializers.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 0d0a4d9a..a4140c0f 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -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()) |
