david / semanticdjango (http://semanticdjango.org/)

fork of django-trunk

The right time for a semantic contrib, that's my pony.

Clone this repository (size: 23.1 MB): HTTPS / SSH
$ hg clone http://code.welldev.org/semanticdjango
commit 6485: 863555ab19c4
parent 6484: 531bfe72e1f8
branch: default
Fixed #10064 -- Corrected handling of aggregate queries that also use select_related(). Thanks to olivius for the report.
russellm
19 months ago

Changed (Δ510 bytes):

raw changeset »

django/db/models/sql/query.py (3 lines added, 2 lines removed)

tests/regressiontests/aggregation_regress/models.py (3 lines added, 0 lines removed)

Up to file-list django/db/models/sql/query.py:

@@ -250,11 +250,12 @@ class BaseQuery(object):
250
250
251
251
                if self.aggregate_select:
252
252
                    aggregate_start = len(self.extra_select.keys()) + len(self.select)
253
                    aggregate_end = aggregate_start + len(self.aggregate_select)
253
254
                    row = tuple(row[:aggregate_start]) + tuple([
254
255
                        self.resolve_aggregate(value, aggregate)
255
256
                        for (alias, aggregate), value
256
                        in zip(self.aggregate_select.items(), row[aggregate_start:])
257
                    ])
257
                        in zip(self.aggregate_select.items(), row[aggregate_start:aggregate_end])
258
                    ]) + tuple(row[aggregate_end:])
258
259
259
260
                yield row
260
261

Up to file-list tests/regressiontests/aggregation_regress/models.py:

@@ -147,6 +147,9 @@ 6
147
147
>>> Book.objects.aggregate(number=Max('pages'), select=Max('pages'))
148
148
{'number': 1132, 'select': 1132}
149
149
150
# Regression for #10064: select_related() plays nice with aggregates
151
>>> Book.objects.select_related('publisher').annotate(num_authors=Count('authors')).values()[0]
152
{'rating': 4.0, 'isbn': u'013790395', 'name': u'Artificial Intelligence: A Modern Approach', 'pubdate': datetime.date(1995, 1, 15), 'price': Decimal("82.8..."), 'id': 5, 'num_authors': 2, 'publisher_id': 3, 'pages': 1132}
150
153
151
154
"""
152
155
}