Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
erdseb opened this issue Jun 11, 2020 · 1 comment
Open

Comments

@erdseb
Copy link

erdseb commented Jun 11, 2020

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!

@pfcodes
Copy link

pfcodes commented Feb 18, 2023

@erdseb did you ever figure this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants