Skip to content

Django rest framework: how to override is_valid on a serializer created with many=True? #8353

Discussion options

You must be logged in to vote

That's confusing isn't it?

There's a bit of a weird dance when you use many=True, which you can see in the __new__ method here.

The normal class creation is bypassed, and you end up with MySerializer(many=True) being equivalent to ListSerializer(child=MySerializer()).

Your custom is_valid() method will be called on any items in the list rather than on the list itself. I can't quite see how it'd lead to the exact behaviour describing but it might help you figure out how to move forward.

One thing that might help you continue to debug your issue would be to stop calling get_serializer() and instead instantiate the serializer directly in the create method. Then once you've done that, switch …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MagnusBrzenk
Comment options

Answer selected by MagnusBrzenk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants