Author: ramiro
Date: 2011-05-21 09:54:25 -0700 (Sat, 21 May 2011)
New Revision: 16254
Modified:
django/trunk/django/db/models/query.py
django/trunk/tests/regressiontests/aggregation_regress/tests.py
Log:
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.
Modified: django/trunk/django/db/models/query.py
===================================================================
--- django/trunk/django/db/models/query.py 2011-05-21 14:41:14 UTC (rev
16253)
+++ django/trunk/django/db/models/query.py 2011-05-21 16:54:25 UTC (rev
16254)
@@ -1132,6 +1132,14 @@
"""
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
Modified: django/trunk/tests/regressiontests/aggregation_regress/tests.py
===================================================================
--- django/trunk/tests/regressiontests/aggregation_regress/tests.py
2011-05-21 14:41:14 UTC (rev 16253)
+++ django/trunk/tests/regressiontests/aggregation_regress/tests.py
2011-05-21 16:54:25 UTC (rev 16254)
@@ -662,6 +662,13 @@
{"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(),
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.