[Django] #37059: `.only(..)` does not check eagerly if the fields exists

11 views
Skip to first unread message

Django

unread,
Apr 22, 2026, 10:37:19 AMApr 22
to django-...@googlegroups.com
#37059: `.only(..)` does not check eagerly if the fields exists
-------------------------------------+-------------------------------------
Reporter: Willem Van Onsem | Type: New
| feature
Status: new | Component:
| Uncategorized
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Django's `QuerySet`s are lazy, but the checks for (most) methods are
eagerly, I think. For example:

{{{
us = User.objects.filter(bla='qux')
}}}

will raise an error.

But `only(..)` seems to be an exception on this. If we use:

{{{
us = User.objects.only('bla')
}}}

it will only raise if we evaluate `us` (enumerate, aggregate,
str/len/...).

It seems nice that `.only(..)` would check eagerly if the fields are
available, otherwise tests might succeed if the queryset is in some cases
not evaluated.

A possible problem might be that `.only(..)` could strictly speaking
mention fields that are not *yet* defined, but later in the chain of ORM
method calls.
--
Ticket URL: <https://code.djangoproject.com/ticket/37059>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 25, 2026, 3:12:15 AMApr 25
to django-...@googlegroups.com
#37059: `.only(..)` does not check eagerly if the fields exists
----------------------------------+--------------------------------------
Reporter: Willem Van Onsem | Owner: Yujin Kim
Type: New feature | Status: assigned
Component: Uncategorized | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Yujin Kim):

* owner: (none) => Yujin Kim
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/37059#comment:1>

Django

unread,
Apr 25, 2026, 8:17:55 PMApr 25
to django-...@googlegroups.com
#37059: `.only(..)` does not check eagerly if the fields exists
-------------------------------------+-------------------------------------
Reporter: Willem Van Onsem | Owner: Yujin Kim
Type: New feature | Status: closed
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Uncategorized => Database layer (models, ORM)
* resolution: => wontfix
* status: assigned => closed

Comment:

Thanks for the suggestion, however, even if feasible, I doubt this is
worth the complexity it would likely add, especially considering that
`defer()` and `only()` are only for advanced use cases.
--
Ticket URL: <https://code.djangoproject.com/ticket/37059#comment:2>
Reply all
Reply to author
Forward
0 new messages