jazzband / django-polymorphic

Improved Django model inheritance with automatic downcasting

Home Page:https://django-polymorphic.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prefetch's to_attr field is not respected for polymorphic models

GregoryAveryWeir opened this issue · comments

If I prefetch_related with a to_attr field, the results of the prefetch do not seem to get saved to an attribute on the query results if the prefetch is for a polymorphic model.

So, using an example from the Django docs, if one does:

voted_choices = Choice.objects.filter(votes__gt=0)
prefetch = Prefetch('choice_set', queryset=voted_choices, to_attr='voted_choices')
Question.objects.prefetch_related(prefetch).get().voted_choices

...the final line will result in an error if Choice is a polymorphic model. Using not_polymorphic() on the queryset doesn't seem to help.