Reputation: 2511
I have a relatively simple question about how serializer.is_valid works when many=True in the Django REST framework.
According to the docs,
When deserializing data, you always need to call is_valid() before attempting to access the deserialized object. If any validation errors occur, the .errors property will contain a dictionary representing the resulting error messages.
If I am trying to serialize and save many docs at a time, and one of the docs is invalid but all the rest are valid, does serializer.is_valid return true or false? The docs seem to suggest serializer.is_valid should be false, but there isn't a concrete example that addresses this subtlety.
Upvotes: 2
Views: 1770
Reputation: 2511
Testing this myself, I will confirm that serializer.is_valid() = False
if ANY of the documents are invalid. It only returns True
if everything is valid.
Upvotes: 3