diff options
| author | Simon Charette <charette.s@gmail.com> | 2024-10-14 19:21:48 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-14 20:21:48 -0300 |
| commit | 53ea4cce2fd08e84b9cdb6363267ccb9525f7060 (patch) | |
| tree | 888b326677c393fcdc6a65bcae96857f484cf7b1 /django/db/models/sql/query.py | |
| parent | 97c05a64ca87253e9789ebaab4b6d20a1b2370cf (diff) | |
Fixed #35744 -- Relabelled external aliases of combined queries.
Just like normal queries, combined queries' outer references might fully
resolve before their reference is assigned its final alias.
Refs #29338.
Thanks Antony_K for the report and example, and thanks Mariusz Felisiak
for the review.
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index aef3f48f10..b7b93c235a 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1021,11 +1021,21 @@ class Query(BaseExpression): if alias == old_alias: table_aliases[pos] = new_alias break + + # 3. Rename the direct external aliases and the ones of combined + # queries (union, intersection, difference). self.external_aliases = { # Table is aliased or it's being changed and thus is aliased. change_map.get(alias, alias): (aliased or alias in change_map) for alias, aliased in self.external_aliases.items() } + for combined_query in self.combined_queries: + external_change_map = { + alias: aliased + for alias, aliased in change_map.items() + if alias in combined_query.external_aliases + } + combined_query.change_aliases(external_change_map) def bump_prefix(self, other_query, exclude=None): """ |
