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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019db59fa7cc-b2cc0cce-21cf-42ac-b5a6-36f7e9c3614f-000000%40eu-central-1.amazonses.com.

Reply via email to