summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-11-17 02:58:59 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-11-17 02:58:59 +0000
commit03b111c6cc2a09ddf8eea50d8d430a305799e9be (patch)
tree7eb2e11c8da33b0bc7df0a8fa35c46c7a1c2f2a9 /tests
parent929b8ff3da31e1b143979a32659f741bbdf5d22b (diff)
[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
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/aggregation_regress/tests.py18
1 files changed, 18 insertions, 0 deletions
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(