diff options
| author | Simon Charette <charette.s@gmail.com> | 2021-04-20 22:25:52 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-04-21 09:49:15 +0200 |
| commit | 6d0cbe42c3d382e5393d4af48185c546bb0ada1f (patch) | |
| tree | d2b5b18450c3215b02493fb00f2b9c265fc12efa /django/db/models/sql/query.py | |
| parent | 34d1905712d33e72c76b3a55a4fc24abbd11be6c (diff) | |
Fixed #32650 -- Fixed handling subquery aliasing on queryset combination.
This issue started manifesting itself when nesting a combined subquery
relying on exclude() since 8593e162c9cb63a6c0b06daf045bc1c21eb4d7c1 but
sql.Query.combine never properly handled subqueries outer refs in the
first place, see QuerySetBitwiseOperationTests.test_subquery_aliases()
(refs #27149).
Thanks Raffaele Salmaso for the report.
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 6c728d17bf..be08c55c7c 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -631,6 +631,10 @@ class Query(BaseExpression): joinpromoter.add_votes(rhs_votes) joinpromoter.update_join_types(self) + # Combine subqueries aliases to ensure aliases relabelling properly + # handle subqueries when combining where and select clauses. + self.subq_aliases |= rhs.subq_aliases + # Now relabel a copy of the rhs where-clause and add it to the current # one. w = rhs.where.clone() |
