1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

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 <charette.s@gmail.com>
This commit is contained in:
David Sanders
2023-11-13 00:45:52 +11:00
committed by Mariusz Felisiak
parent 1b56b24f81
commit b863c5ffde
4 changed files with 23 additions and 0 deletions

View File

@@ -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