#12328: subqueries in django 1.1 behave oddly
---------------------------------------------------+------------------------
          Reporter:  wdoekes                       |         Owner:  
marcosmoyano
            Status:  assigned                      |     Milestone:  1.2        
 
         Component:  Database layer (models, ORM)  |       Version:  1.1        
 
        Resolution:                                |      Keywords:             
 
             Stage:  Accepted                      |     Has_patch:  1          
 
        Needs_docs:  0                             |   Needs_tests:  0          
 
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by marcosmoyano):

 There's still an issue in the delete() method. Although modifying the
 while statemente solves the issue, this solution requires and extra query,
 which is not the desired solution.
 Here's a closer look at the problem.
 {{{
 In [1]: from ticket_12328.models import *

 In [2]: M.objects.create(id=1)
 Out[2]: <M: M(id=1)>

 In [3]: M.objects.create(id=2)
 Out[3]: <M: M(id=2)>

 In [4]: M.objects.create(id=3)
 Out[4]: <M: M(id=3)>

 In [5]: M.objects.all()
 Out[5]: [<M: M(id=1)>, <M: M(id=2)>, <M: M(id=3)>]

 In [6]: M.objects.filter(id__in=M.objects.order_by('id')[:1]).delete()
 > /usr/lib/python2.6/site-packages/django/db/models/query.py(433)delete()
     432         import ipdb;ipdb.set_trace()
 --> 433         while 1:
     434         #for element in xrange(del_query.count()):


 ipdb> print del_query.query
 SELECT "ticket_12328_m"."id" FROM "ticket_12328_m" WHERE
 "ticket_12328_m"."id" IN (SELECT U0."id" FROM "ticket_12328_m" U0 ORDER BY
 U0."id" ASC LIMIT 1)
 ipdb> n
 > /usr/lib/python2.6/site-packages/django/db/models/query.py(437)delete()
     436             # objects that are related to the objects that are to
 be deleted.

 --> 437             seen_objs = CollectedObjects(seen_objs)
     438             for object in del_query[:CHUNK_SIZE]:

 }}}

 On line #438 every time del_query gets evaluated it will return the first
 element from the table (ordered by id) until there are no more elements to
 consume.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12328#comment:8>
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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to