Opened 3 weeks ago

Closed 3 weeks ago

#37059 closed New feature (wontfix)

`.only(..)` does not check eagerly if the fields exists

Reported by: Willem Van Onsem Owned by: Yujin Kim
Component: Database layer (models, ORM) Version: 6.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django's QuerySets 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.

Change History (2)

comment:1 by Yujin Kim, 3 weeks ago

Owner: set to Yujin Kim
Status: newassigned

comment:2 by Tim Graham, 3 weeks ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: wontfix
Status: assignedclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top