Django rest framework: how to override is_valid
on a serializer created with many=True
?
#8353
-
I have a puzzling question that I posted to SO -- and would REALLY appreciate some help! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's confusing isn't it? There's a bit of a weird dance when you use The normal class creation is bypassed, and you end up with Your custom One thing that might help you continue to debug your issue would be to stop calling Hope that helps a little |
Beta Was this translation helpful? Give feedback.
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 toListSerializer(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 thecreate
method. Then once you've done that, switch …