Serializer with PrimaryKeyRelatedField many=True produces lots of queries when is_valid is called

236 views
Skip to first unread message

Wasp

unread,
Jul 12, 2018, 3:54:44 AM7/12/18
to Django REST framework
I'm using Serializers to transform primary keys into model instances with DRF by using the PrimaryKeyRelatedField. 
However, when I run the is_valid() method on the serializers to get the validated data for every primary key a query is produced by performing a get on the provided queryset. 
With large numbers this becomes very inefficient. Is there a way to trigger a .filter() on the queryset or a better way of doing this? I know I can just do a filter on the queryset myself but I like the structured way of doing this via Serializers.

Thanks!

Alex Newman

unread,
Jul 17, 2019, 1:54:05 PM7/17/19
to Django REST framework
Hi! Exactly the same problem, any chance you figured out a good solution for it? setup_eager_loading doesn't help in this case at all
Reply all
Reply to author
Forward
0 new messages