Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit a8598c7de2d600fa4c3b4e6d80c2fafb9063215b 1 parent f60d428
Ramiro Morales authored May 21, 2011
8  django/db/models/query.py
@@ -1132,6 +1132,14 @@ def update(self, **kwargs):
1132 1132
         """
1133 1133
         return 0
1134 1134
 
  1135
+    def aggregate(self, *args, **kwargs):
  1136
+        """
  1137
+        Return a dict mapping the aggregate names to None
  1138
+        """
  1139
+        for arg in args:
  1140
+            kwargs[arg.default_alias] = arg
  1141
+        return dict([(key, None) for key in kwargs])
  1142
+
1135 1143
     # EmptyQuerySet is always an empty result in where-clauses (and similar
1136 1144
     # situations).
1137 1145
     value_annotation = False
7  tests/regressiontests/aggregation_regress/tests.py
@@ -662,6 +662,13 @@ def test_empty_filter_aggregate(self):
662 662
             {"pk__count": None}
663 663
         )
664 664
 
  665
+    def test_none_call_before_aggregate(self):
  666
+        # Regression for #11789
  667
+        self.assertEqual(
  668
+            Author.objects.none().aggregate(Avg('age')),
  669
+            {'age__avg': None}
  670
+        )
  671
+
665 672
     def test_annotate_and_join(self):
666 673
         self.assertEqual(
667 674
             Author.objects.annotate(c=Count("friends__name")).exclude(friends__name="Joe").count(),

0 notes on commit a8598c7

Please sign in to comment.
Something went wrong with that request. Please try again.