Permalink
Browse files

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
  • Loading branch information...
1 parent f60d428 commit a8598c7de2d600fa4c3b4e6d80c2fafb9063215b @ramiro ramiro committed May 21, 2011
Showing with 15 additions and 0 deletions.
  1. +8 −0 django/db/models/query.py
  2. +7 −0 tests/regressiontests/aggregation_regress/tests.py
View
8 django/db/models/query.py
@@ -1132,6 +1132,14 @@ def update(self, **kwargs):
"""
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
View
7 tests/regressiontests/aggregation_regress/tests.py
@@ -662,6 +662,13 @@ def test_empty_filter_aggregate(self):
{"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(),

0 comments on commit a8598c7

Please sign in to comment.