GeeWee / django-auto-prefetching

Automatic prefetching for Django
MIT License
231 stars 18 forks source link

BUG: get_serializer_class not supported #47

Open creyD opened 2 years ago

creyD commented 2 years ago

When using the AutoPrefetchViewSetMixin errors get thrown for fields which are not on the original serializer_class (?). We have a GenericViewSet which has a main model and actions which return different serializers (basically nested info). When using the Mixin, the following error appears:

b'{"message":"Invalid field name(s) given in select_related: \'gateway\', \'unit_id\', \'protocol\', \'type\', \'manufacturer\', \'conf\'. Choices are: address_id, type_id, parent_id, created_by, company_id","status":500,"error":true,"detail":""}'

Where the select_related fields are the actual fields of the serializer being used and the Choices are the fields on the main model/ serializer_class for this ViewSet.

creyD commented 2 years ago

Our current workaround is to exclude these fields manually, but this isn't really a solution.

creyD commented 2 years ago

I see this is a problem known, as it is mentioned in the TODO.txt

GeeWee commented 2 years ago

Yeah this is is probably true - I would absolutely accept a PR with a test or two that fixes this issue - but I haven't used this project for a long time, so I don't have the time to do anything about it myself unfortunately.