Skip to content

5.0's generic prefetch fights with fetch_generic_relations #544

Open
@gone

Description

@gone

I have a situation where I have three models that can be targets, and each one needs different optimizations.
An optimal prefetch looks like:

class MyActionManager(ActionManager):
    def get_queryset(self):
        prefetch_target = GenericPrefetch(
            "target", [
                Celebration.objects.select_related('type', 'user'),
                Milestone.objects.select_related('type', 'user'),
                Review.objects.select_related('author').prefetch_related('users', 'locations', 'teams')
            ]
        )

        prefetch_actor = GenericPrefetch(
            "actor", [
                User.objects.all(),
            ]
        )
        return MyActionQuerySet(self.model, using=self._db).prefetch_related(prefetch_actor).prefetch_related(prefetch_target)

If we add in fetch_generic_realtions before the prefetch it will break the generic prefetch behavior.

I think possibly the GFK QuerySet might be able to use GenericPrefetch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions