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 --- django/db/models/sql/compiler.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'django/db/models/sql/compiler.py') diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index b28dc925ba..7cec040cee 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -877,6 +877,8 @@ class SQLCompiler: if self._meta_ordering: order_by = None if having: + if not grouping: + result.extend(self.connection.ops.force_group_by()) result.append("HAVING %s" % having) params.extend(h_params) -- cgit v1.3