summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2011-05-21 16:54:25 +0000
committerRamiro Morales <cramm0@gmail.com>2011-05-21 16:54:25 +0000
commita8598c7de2d600fa4c3b4e6d80c2fafb9063215b (patch)
tree4409ccf2ad0fa19de32be485c3c0824fa1e24965
parentf60d42846365b2bf2f1c9bc7a3007c303122a20b (diff)
Fixed #11789 -- Fixed aggregates so it interacts with QuerySet none() in a way consistent with other empty query sets. Thanks alexr for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16254 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/query.py8
-rw-r--r--tests/regressiontests/aggregation_regress/tests.py7
2 files changed, 15 insertions, 0 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 9c3aeaa8d3..6a6a82968f 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1132,6 +1132,14 @@ class EmptyQuerySet(QuerySet):
"""
return 0
+ def aggregate(self, *args, **kwargs):
+ """
+ Return a dict mapping the aggregate names to None
+ """
+ for arg in args:
+ kwargs[arg.default_alias] = arg
+ return dict([(key, None) for key in kwargs])
+
# EmptyQuerySet is always an empty result in where-clauses (and similar
# situations).
value_annotation = False
diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py
index 15692b6422..49e1e611e9 100644
--- a/tests/regressiontests/aggregation_regress/tests.py
+++ b/tests/regressiontests/aggregation_regress/tests.py
@@ -662,6 +662,13 @@ class AggregationTests(TestCase):
{"pk__count": None}
)
+ def test_none_call_before_aggregate(self):
+ # Regression for #11789
+ self.assertEqual(
+ Author.objects.none().aggregate(Avg('age')),
+ {'age__avg': None}
+ )
+
def test_annotate_and_join(self):
self.assertEqual(
Author.objects.annotate(c=Count("friends__name")).exclude(friends__name="Joe").count(),