From b863c5ffde0bafa5eaa9f262103eaeb71877787c Mon Sep 17 00:00:00 2001 From: David Sanders Date: Mon, 13 Nov 2023 00:45:52 +1100 Subject: Fixed #34967 -- Fixed queryset crash when grouping by constants on SQLite < 3.39. On SQLite < 3.39, this forces a GROUP BY clause with a HAVING clause when no grouping is specified. Co-authored-by: Simon Charette --- tests/aggregation/tests.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/aggregation') diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 8d8e46e312..a073d01590 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -2126,6 +2126,15 @@ class AggregateTestCase(TestCase): qs = Publisher.objects.filter(pk__in=author_qs) self.assertCountEqual(qs, [self.p1, self.p2, self.p3, self.p4]) + def test_having_with_no_group_by(self): + author_qs = ( + Author.objects.values(static_value=Value("static-value")) + .annotate(sum=Sum("age")) + .filter(sum__gte=0) + .values_list("sum", flat=True) + ) + self.assertEqual(list(author_qs), [337]) + class AggregateAnnotationPruningTests(TestCase): @classmethod -- cgit v1.3