Serializer with many=true missuses the respective validate()

189 views
Skip to first unread message

Anton Savitskiy

unread,
Sep 4, 2021, 7:55:29 AM9/4/21
to Django REST framework

Hello,

I have faced the problem because I lack understanding of the logic behind:  

There are 2 serializers CreateSerializer(child) and BulkCreateSerializer(parent). They are connected via list_serializer_class. I have overridden create() and validate() methods for both serializers and expect them to trigger respectively on whether a single instance is coming via POST or a list of instances.

However, when I am sending a post request with a list of instances serializer does switch to many=true but uses validate() that belongs to child CreateSerializer instead of dedicated BulkCreateSerializer, which runs me into errors of course.

So my question is, what could be the logic under the hood, that prevents my serializers to distribute the items for validation respectively? And how to make it work that way?

Please see the opened question on StackOverflow with the code examples provided:

https://stackoverflow.com/questions/69030259/django-drf-serializer-with-many-true-missuses-the-respective-validate

Reply all
Reply to author
Forward
0 new messages