#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.