summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-01-23 11:03:48 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-01-23 11:03:48 +0000
commit0e15932be392ab56fa0087f9c13b234af7749e2e (patch)
tree63dd18930c2b230f53713ce5d1fb220d9fde76a8 /django/db/models/sql/query.py
parented3d2735a2eb5d279e2098e14437eb9e445498c6 (diff)
Fixed #10089 -- Corrected handling of aggregates when the query set contains no items (and the cursor returns None). Thanks to Kyle Fox for the report, and david for the initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9786 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 8a4f88a9c8..12a3705674 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -217,6 +217,8 @@ class BaseQuery(object):
to return Decimal and long types when they are not needed.
"""
if value is None:
+ if aggregate.is_ordinal:
+ return 0
# Return None as-is
return value
elif aggregate.is_ordinal:
@@ -295,10 +297,14 @@ class BaseQuery(object):
query.related_select_cols = []
query.related_select_fields = []
+ result = query.execute_sql(SINGLE)
+ if result is None:
+ result = [None for q in query.aggregate_select.items()]
+
return dict([
(alias, self.resolve_aggregate(val, aggregate))
for (alias, aggregate), val
- in zip(query.aggregate_select.items(), query.execute_sql(SINGLE))
+ in zip(query.aggregate_select.items(), result)
])
def get_count(self):