#13442: only() and defer() will always select id
-----------------------------+----------------------------------------------
 Reporter:  mampf            |       Owner:            
   Status:  new              |   Milestone:            
Component:  ORM aggregation  |     Version:  1.1       
 Keywords:                   |       Stage:  Unreviewed
Has_patch:  0                |  
-----------------------------+----------------------------------------------
 Hi there,

 when you do a query with defer() or only(), you will still execute a
 SELECT query including the object's id. This makes it impossible to use
 distinct() on it.
 {{{
 #!python
 last_5_uploaded_files = UploadFile.objects.order_by('upload_time')[:5]
 last_changed_list = MainObject.objects \
     .filter(upload_file__in=last_5_uploaded_files) \
     .only('field_1', 'hostname', 'target', 'modifed_date') \
     .distinct() \
     .order_by('-modified_date')[:50]

     response = render_to_response('output/mainobject_list.html',
     {'object_list': last_changed_list,})

     connection.queries
     print("")
     # Still includes MainObject.id! WHY?
     print("current queue: %s" % connection.queries)
     print("")

     return response
 }}}
 Now if I print the executed SQL using connection.queries I get an SQL
 statement which includes queryset.id. This is why my distinct won't word -
 I want a distinct list created without id.[[BR]]
 On the other hand, '''.values('field_1', 'field_n')''' does work. But this
 way I do not get the foreign table resolved, just it's id.

 Please change only() and defer(), so it doesn't select the id in any case.

 Thanks

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13442>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to