diff options
| author | David Wobrock <david.wobrock@gmail.com> | 2021-09-29 00:00:50 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-29 20:53:16 +0200 |
| commit | b2a0978610413e4cd5ebb716b8bfa7803dff8d5b (patch) | |
| tree | 4ffaefa0f303e51266852bb8251eef28a5f8da54 /tests/db_functions | |
| parent | aab76433ed585ebe997b94547e0d790605e01ad9 (diff) | |
[4.0.x] Fixed #33018 -- Fixed annotations with empty queryset.
Thanks Simon Charette for the review and implementation idea.
Backport of dd1fa3a31b4680c0d3712e6ae122b878138580c7 from main
Diffstat (limited to 'tests/db_functions')
| -rw-r--r-- | tests/db_functions/comparison/test_coalesce.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/db_functions/comparison/test_coalesce.py b/tests/db_functions/comparison/test_coalesce.py index 8ba4b01fe6..1093079d68 100644 --- a/tests/db_functions/comparison/test_coalesce.py +++ b/tests/db_functions/comparison/test_coalesce.py @@ -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) |
