Issue with implementing update method on ListSerializer and unique constraints

151 views
Skip to first unread message

Tj Johnson

unread,
Feb 13, 2023, 8:48:43 PM2/13/23
to Django REST framework
I had a use case where I had to implement a multiple update endpoint; and for the most part I followed docs https://www.django-rest-framework.org/api-guide/serializers/#customizing-multiple-update

however in my case I could not include the pk/id on the child serializer because this is being used for integration work from an external data source that is unaware of our pks.

The instance kwarg that I pass to the ListSerializer is a queryset that filters on an alternate key.

This queryset also gets passed as the instance kwarg to the child serializer, where it expects an object instance and not a queryset.

The issue manifested as an AttributeError in the validators where a queryset has no attribute pk: on this line https://github.com/encode/django-rest-framework/blob/4abfa28e0879e2df45937ac8c7a9ffa161561955/rest_framework/validators.py#L60

I'm still unsure of how to appropriately pass single instances, or lack thereof to the child serializer for validation.  Another thought I had was to override some method on the child (before validation) to set self.instance

Reply all
Reply to author
Forward
0 new messages