Feature Request: Add an option to allow ListSerializer to continue with errors #7828
Unanswered
EmperorArthur
asked this question in
Ideas & Suggestions
Replies: 1 comment 3 replies
-
Good first step here would be to address this yourself perhaps with a customized Once you've demo'ed something there, either as a code snippet or as a third party package, then others would be able to reuse it too, and we could consider linking to it from the docs. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I often deal with a data access pastern that is probably quite common in the wild, and wanted to discuss the possibility of addressing it.
We pull in tens of thousands of machine generated data points, then pass them to a serializer before saving. The problem is that there are often a few records which are incorrect. In our case, it's often a string that can not be blank in the CSV file, but the same general thing applies to any validator.
Proposal
Add an
allow_failures
kwarg to ListSerializer. In this mode,is_valid
would succeed in setting validated_data based on all the data which had no errors, but everything else would stay the same.Details
to_internal_value
returns a list of the objects which succeeded, but also sets "self._errors" to a list of errors that fails.raise ValidationError(errors)
toself._errors = errors
is_valid
to clear "self.errors" before callingself.run_validation(self.initial_data)
, instead of afterwards.This presents a more granular approach versus all or nothing, and explicitly allows gratefully handling systems which occasionally "hickup".
I have personally use code similar to the above for over a year at this point, and have found it invaluable. Maybe others will as well.
Beta Was this translation helpful? Give feedback.
All reactions