#37059 new New feature

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

Reported by: Willem Van Onsem Owned by:
Component: Uncategorized 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 (0)

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