mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #12687 -- fixed an issue with aggregates and counts in conjunction with annotations where the QuerySet was provably empty.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14586 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3e9d2f81c5
commit
4276b5197b
4 changed files with 36 additions and 4 deletions
|
@ -622,6 +622,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()
|
||||
)
|
||||
|
||||
@skipUnlessDBFeature('supports_stddev')
|
||||
def test_stddev(self):
|
||||
self.assertEqual(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue