diff options
| author | Simon Charette <charette.s@gmail.com> | 2022-09-28 00:44:46 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-10-06 11:38:03 +0200 |
| commit | 3d734c09ff0138441dfe0a59010435871d17950f (patch) | |
| tree | 26db20983d0b6931bfc7537a81cdc310e7a2fade /django/db/models/sql/compiler.py | |
| parent | 04518e310d4552ff7595a34f5a7f93487d78a406 (diff) | |
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.
Diffstat (limited to 'django/db/models/sql/compiler.py')
| -rw-r--r-- | django/db/models/sql/compiler.py | 9 |
1 files changed, 7 insertions, 2 deletions
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: |
