#34123: Ambiguous aliases in ordering on combined queries with select_related().
-------------------------------------+-------------------------------------
Reporter: Shai Berger | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: select_related | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Making sure the inner queries are generated with aliases for each columns,
which is something we already have the machinery for, should be enough to
address the issue.
We just have to make sure the queries are compiled by passing
`with_col_aliases=True` to their compiler's `as_sql`, something like
{{{#!diff
diff --git a/django/db/models/sql/compiler.py
b/django/db/models/sql/compiler.py
index 3097500be4..8b727f42ce 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -563,7 +563,7 @@ def get_combinator_sql(self, combinator, all):
*self.query.annotation_select,
)
)
- part_sql, part_args = compiler.as_sql()
+ part_sql, part_args =
compiler.as_sql(with_col_aliases=True)
if compiler.query.combinator:
# Wrap in a subquery if wrapping in parentheses isn't
# supported
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34123#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018419c27749-e3e8c2b3-bf4d-49cf-bedc-a3eee0beb6dc-000000%40eu-central-1.amazonses.com.