#30052: QuerySet.only() doesn't support annotations
-------------------------------------+-------------------------------------
     Reporter:  Kal Sze              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Kal Sze):

 Replying to [comment:4 Tim Graham]:
 > I'm not sure. Please test `only()` without arguments. If it works, it
 might be worth adding tests for (if not already in Django's tests) and
 documenting.
 So I did a quick TIAS and here is what I found out, by printing
 `QuerySet.query`:

 - `QuerySet.only()` without any argument doesn't defer any field; it would
 select every field of the model plus any annotation added to the QuerySet;
 - `QuerySet.only('some_field')` would select the `id`, `some_field`, plus
 any annotation added to the QuerySet.

 Ideally, it would be great if `only()` behaved in one of two ways:
 - without any argument, defer all fields except the id and annotations;
 or
 - accept annotated field names

 But it might break old apps and it's too late to change.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30052#comment:5>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.d945a12444513ccd6659288033f1dc83%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to