Re: [Django] #35442: QuerySet.only() causes n+1 queries with reverse foreign key relation when related id is not included. (was: N+1 queries from RelatedManager + only("pk"))

1 view
Skip to first unread message

Django

unread,
Dec 2, 2025, 10:38:22 AM (16 hours ago) Dec 2
to django-...@googlegroups.com
#35442: QuerySet.only() causes n+1 queries with reverse foreign key relation when
related id is not included.
-------------------------------------+-------------------------------------
Reporter: REGNIER Guillaume | Owner: Rish
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* summary: N+1 queries from RelatedManager + only("pk") =>
QuerySet.only() causes n+1 queries with reverse foreign key relation
when related id is not included.

Comment:

#36764 was a duplicate.
--
Ticket URL: <https://code.djangoproject.com/ticket/35442#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages