mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #32126 -- Fixed grouping by Case() annotation without cases.
Co-authored-by: Simon Charette <charettes@users.noreply.github.com>
This commit is contained in:
parent
4343430e9c
commit
0e7a45fca0
2 changed files with 30 additions and 0 deletions
|
@ -1148,6 +1148,31 @@ class CaseExpressionTests(TestCase):
|
|||
lambda x: x[1:]
|
||||
)
|
||||
|
||||
def test_aggregation_empty_cases(self):
|
||||
tests = [
|
||||
# Empty cases and default.
|
||||
(Case(output_field=IntegerField()), None),
|
||||
# Empty cases and a constant default.
|
||||
(Case(default=Value('empty')), 'empty'),
|
||||
# Empty cases and column in the default.
|
||||
(Case(default=F('url')), ''),
|
||||
]
|
||||
for case, value in tests:
|
||||
with self.subTest(case=case):
|
||||
self.assertQuerysetEqual(
|
||||
CaseTestModel.objects.values('string').annotate(
|
||||
case=case,
|
||||
integer_sum=Sum('integer'),
|
||||
).order_by('string'),
|
||||
[
|
||||
('1', value, 1),
|
||||
('2', value, 4),
|
||||
('3', value, 9),
|
||||
('4', value, 4),
|
||||
],
|
||||
transform=itemgetter('string', 'case', 'integer_sum'),
|
||||
)
|
||||
|
||||
|
||||
class CaseDocumentationExamples(TestCase):
|
||||
@classmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue