From 0e15932be392ab56fa0087f9c13b234af7749e2e Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 23 Jan 2009 11:03:48 +0000 Subject: 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 --- django/db/models/sql/query.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'django/db/models/sql') 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): -- cgit v1.3