mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
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
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user