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

Issue with basic django admin and "LogEntry" #27

Open
pakal opened this issue May 27, 2019 · 4 comments
Open

Issue with basic django admin and "LogEntry" #27

pakal opened this issue May 27, 2019 · 4 comments

Comments

@pakal
Copy link

pakal commented May 27, 2019

Accessing the Django2.2.1 admin on a rather simple project, with nplusone 1.0.0, raises this error :

"Potential unnecessary eager load detected on LogEntry.user"

I don't get what this means, since LogEntry.user is a ForeignKey, how could it lead to a heavy loading ? What kind of problem does nplusone report in this case, is it with the User model or with the LogEntry model ?

@pakal
Copy link
Author

pakal commented May 27, 2019

Django debug toolbar reports that only 1 sql query is issue on /admin/ page, the one below.
But this query IS used, there is a list of recent user actions in the HTML response. Could it be a "false positive"?

SELECT ••• FROM "django_admin_log" INNER JOIN "accounts_user" ON ("django_admin_log"."user_id" = "accounts_user"."id") LEFT OUTER JOIN "django_content_type" ON ("django_admin_log"."content_type_id" = "django_content_type"."id") WHERE "django_admin_log"."user_id" = '1' ORDER BY "django_admin_log"."action_time" DESC LIMIT 10

@hartwork
Copy link

There are two typoes of anomalies that nplusone reports about:

  • a) N+1 that should be prevented
  • b) N+1 protection costs that do not pair with an actual N+1 problem.

The query above contains two joins. If at least one of these is the result of use of select_related, warning "unnecessary eager load" is justified if some of the joined-in data turns out unused. That would be case (b).

My impression right now: Not a bug in nplusone but suboptimally performing code in Django admin. What do you think?

@erdseb
Copy link

erdseb commented Jun 4, 2020

This workaround did the trick for me:

NPLUSONE_WHITELIST = [
    {'model': 'admin.LogEntry', 'label': 'unused_eager_load'},
]

@pakal
Copy link
Author

pakal commented Jun 24, 2020

Allright I'll check the next time that it appears somewhere - i'm not on this project anymore ; maybe it issued a select_related() on User and never used it, indeeed.

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

3 participants