mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #33018 -- Fixed annotations with empty queryset.
Thanks Simon Charette for the review and implementation idea.
This commit is contained in:
committed by
Mariusz Felisiak
parent
ad36a198a1
commit
dd1fa3a31b
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user