You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How do I create validators for bulk APIs? For example a bulk user endpoint that would validate that the uploaded data didn't contain any duplicate emails. The issue is that the current list serializers validate each object individually but not as a group so it is possible for it to get a validation error raised when I call serializer.save() after half of the objects were saved and I hit the duplicate. This can be a big problem where the users expect these to happen in a transaction like scenario where it either works for all or sends back an error and doesn't make any changes. Instead, it is making some changes and then sending back a 500 with the Django validation error.
I propose being able to write functions like validate_emails on a bulk serializer like class and get a list of all the emails that were uploaded in the bulk. That way I could easily write something like if len(emails) != len(set(emails)): raise ValidationError('Duplicate emails).
Activity
xordoquy commentedon Jan 19, 2017
The discussion group is the best place to take this discussion and other usage questions. Thanks!