Kaydet (Commit) a8598c7d authored tarafından Ramiro Morales's avatar Ramiro Morales

Fixed #11789 -- Fixed aggregates so it interacts with QuerySet none() in a way…

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
üst f60d4284
...@@ -1132,6 +1132,14 @@ class EmptyQuerySet(QuerySet): ...@@ -1132,6 +1132,14 @@ class EmptyQuerySet(QuerySet):
""" """
return 0 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 # EmptyQuerySet is always an empty result in where-clauses (and similar
# situations). # situations).
value_annotation = False value_annotation = False
......
...@@ -662,6 +662,13 @@ class AggregationTests(TestCase): ...@@ -662,6 +662,13 @@ class AggregationTests(TestCase):
{"pk__count": None} {"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): def test_annotate_and_join(self):
self.assertEqual( self.assertEqual(
Author.objects.annotate(c=Count("friends__name")).exclude(friends__name="Joe").count(), Author.objects.annotate(c=Count("friends__name")).exclude(friends__name="Joe").count(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment