From 03b111c6cc2a09ddf8eea50d8d430a305799e9be Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 17 Nov 2010 02:58:59 +0000 Subject: [1.2.X] Fixed #12687 -- fixed an issue with aggregates and counts in conjunction with annotations where the QuerySet was provably empty. Backport of [14586]. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14587 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/aggregation_regress/tests.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py index 58d0b2748f..2429ffec94 100644 --- a/tests/regressiontests/aggregation_regress/tests.py +++ b/tests/regressiontests/aggregation_regress/tests.py @@ -641,6 +641,24 @@ class AggregationTests(TestCase): lambda: Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age')) ) + def test_empty_filter_count(self): + self.assertEqual( + Author.objects.filter(id__in=[]).annotate(Count("friends")).count(), + 0 + ) + + def test_empty_filter_aggregate(self): + self.assertEqual( + Author.objects.filter(id__in=[]).annotate(Count("friends")).aggregate(Count("pk")), + {"pk__count": None} + ) + + def test_annotate_and_join(self): + self.assertEqual( + Author.objects.annotate(c=Count("friends__name")).exclude(friends__name="Joe").count(), + Author.objects.count() + ) + if run_stddev_tests(): def test_stddev(self): self.assertEqual( -- cgit v1.3