mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Raise assertion error if calling .save() on a serializer with errors. Closes #2098.
This commit is contained in:
parent
6ac79b8223
commit
79e18a2a06
|
@ -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())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user