#18279: Django ORM calculation of aggregate position is select queries
----------------------------------------------+--------------------
     Reporter:  deepak@…                      |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.4
     Severity:  Normal                        |   Keywords:  orm
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 Hello,
 I believe I have discovered this bug in django 1.4 ORM. I am not familiar
 enough with the ORM to write a patch. Here,
 
https://github.com/django/django/blob/master/django/db/models/sql/compiler.py#L784

 {{{
 aggregate_start = len(self.query.extra_select.keys()) +
 len(self.query.select)
 aggregate_end = aggregate_start + len(self.query.aggregate_select)
 row = tuple(row[:aggregate_start]) + tuple([
                         self.query.resolve_aggregate(value, aggregate,
 self.connection)
                         for (alias, aggregate), value
                         in zip(self.query.aggregate_select.items(),
 row[aggregate_start:aggregate_end])
                     ]) + tuple(row[aggregate_end:])

 }}}
 I believe aggregate_start should be calculated using the number of non-
 deferred fields rather than the length of query.select which is equal to
 the all the fields in the model.  During some debugging I found that
 aggregate_start was being calculated way past the number of elements in
 the db returned row. Strangely, the bug has no side-effects because
 resolve_aggregate is never called since it operates on an empty list.

 Lastly, I think this is a bug but I am not sure why this has no side-
 effects.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18279>
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 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