Skip to content

Prefetch's to_attr field is not respected for polymorphic models #498

@GregoryAveryWeir

Description

@GregoryAveryWeir

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions