Skip to content

[Django] nplusone complains both with and without prefetch_related #34

@erdseb

Description

@erdseb

Hi!

I have a case where nplusone first complains that a prefetch_related is missing and once I add that it complains that the new prefetch_related is over-eager.

In more detail:

  • The related part of the model is:
    • Three Models: P, N and U
    • Query starts at P, i.e. P.objects.[..]
    • P has an m2m relation to N
    • N has a foreign key towards U
  • Initial error is:
    Potential n+1 query detected on "N.u"
  • Once I add .prefetch_related('n__u') it changes to:
    Potential unnecessary eager load detected on "P.n"

Any thoughts other than whitelisting for a workaround?

Thanks in advance!

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