#7791: len() on queryset with distinct ordered by child's field crashes
------------------------------+---------------------------------------------
 Reporter:  isagalaev         |       Owner:  mtredinnick
   Status:  new               |   Milestone:             
Component:  Database wrapper  |     Version:  SVN        
 Keywords:                    |       Stage:  Unreviewed 
Has_patch:  0                 |  
------------------------------+---------------------------------------------
 Given this model:

 {{{
 #!python
 class Restaurant(models.Model):
     title = models.CharField(max_length=50)

 class Pizza(models.Model):
     restaurant = models.ForeignKey(Restaurant)
     title = models.CharField(max_length=50)
 }}}

 and this data (one test record for each model):

 {{{
 [
   {
     "pk": 1,
     "model": "main.restaurant",
     "fields": {
       "title": "Karlo"
     }
   },
   {
     "pk": 1,
     "model": "main.pizza",
     "fields": {
       "title": "Margherita",
       "restaurant": 1
     }
   }
 ]
 }}}

 calling len() on a queryset with distinct ordered by child's field:

 {{{
 #!python
 len(Restaurant.objects.order_by('pizza__title').distinct())
 }}}

 gives this traceback:

 {{{
 Traceback (most recent call last):
   File "./manage.py", line 13, in <module>
     len(Restaurant.objects.order_by('pizza__title').distinct())
   File "/home/isagalaev/py/django/db/models/query.py", line 153, in
 __len__
     self._result_cache = list(self.iterator())
   File "/home/isagalaev/py/django/db/models/query.py", line 273, in
 iterator
     obj = self.model(*row[index_start:])
   File "/home/isagalaev/py/django/db/models/base.py", line 184, in
 __init__
     raise IndexError("Number of args exceeds number of fields")
 IndexError: Number of args exceeds number of fields
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/7791>
Django Code <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