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 10:32:39 +0200 |
| commit | 48e19bae49f271cccbb8a8f4549c9366b7cecac6 (patch) | |
| tree | cc52844e77b7884251c60071933b86751249035a /django/db/models/sql/query.py | |
| parent | 1cc2eaf02d2aa64f7ca4ef52f3d9f13381540007 (diff) | |
[3.2.x] 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.
Backport of 6d0cbe42c3d382e5393d4af48185c546bb0ada1f from main
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 2c6a50934d..73c9e5ca4f 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -634,6 +634,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() |
