1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #33018 -- Fixed annotations with empty queryset.

Thanks Simon Charette for the review and implementation idea.
This commit is contained in:
David Wobrock
2021-09-29 00:00:50 +02:00
committed by Mariusz Felisiak
parent ad36a198a1
commit dd1fa3a31b
5 changed files with 33 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
from django.db.models import TextField
from django.db.models import Subquery, TextField
from django.db.models.functions import Coalesce, Lower
from django.test import TestCase
from django.utils import timezone
@@ -70,3 +70,14 @@ class CoalesceTests(TestCase):
authors, ['John Smith', 'Rhonda'],
lambda a: a.name
)
def test_empty_queryset(self):
Author.objects.create(name='John Smith')
tests = [
Author.objects.none(),
Subquery(Author.objects.none()),
]
for empty_query in tests:
with self.subTest(empty_query.__class__.__name__):
qs = Author.objects.annotate(annotation=Coalesce(empty_query, 42))
self.assertEqual(qs.first().annotation, 42)