From 3d734c09ff0138441dfe0a59010435871d17950f Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Wed, 28 Sep 2022 00:44:46 -0400 Subject: Refs #33992 -- Refactored subquery grouping logic. This required moving the combined queries slicing logic to the compiler in order to allow Query.exists() to be called at expression resolving time. It allowed for Query.exists() to be called at Exists() initialization time and thus ensured that get_group_by_cols() was operating on the terminal representation of the query that only has a single column selected. --- django/db/models/sql/compiler.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (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 e4605918d9..e9f99fa838 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -535,8 +535,8 @@ class SQLCompiler: if not query.is_empty() ] if not features.supports_slicing_ordering_in_compound: - for query, compiler in zip(self.query.combined_queries, compilers): - if query.low_mark or query.high_mark: + for compiler in compilers: + if compiler.query.is_sliced: raise DatabaseError( "LIMIT/OFFSET not allowed in subqueries of compound statements." ) @@ -544,6 +544,11 @@ class SQLCompiler: raise DatabaseError( "ORDER BY not allowed in subqueries of compound statements." ) + elif self.query.is_sliced and combinator == "union": + limit = (self.query.low_mark, self.query.high_mark) + for compiler in compilers: + if not compiler.query.is_sliced: + compiler.query.set_limits(*limit) parts = () for compiler in compilers: try: -- cgit v1.3