#32627: Multi-model union fails with .first()
-------------------------------------+-------------------------------------
Reporter: Iuri de | Owner: nobody
Silvio |
Type: Bug | Status: new
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django 3.2 fails with this query:
{{{#!python
qs1 = Celebrity.objects.all()
qs2 = ReservedName.objects.all()
qs1.union(qs2).values_list('name').first()
}}}
It worked until Django 3.1.8. This commit[1] to be exactly.
[1]
https://github.com/django/django/commit/464a4c0c59277056b5d3c1132ac1b4c6085aee08
This is the broken generated query. In the second query, it fetches from
the first table.
{{{#!sql
SQL
SELECT
"queries_celebrity"."name",
"queries_celebrity"."id" AS "__orderbycol2"
FROM
"queries_celebrity"
UNION
SELECT
"queries_reservedname"."name",
"queries_celebrity"."id" AS "__orderbycol2" -- HERE IS THE PROBLEM
FROM
"queries_reservedname"
ORDER BY
(2) ASC
LIMIT
1
}}}
Before, it was:
{{{#!sql
SQL
SELECT
"queries_celebrity"."name",
"queries_celebrity"."id"
FROM
"queries_celebrity"
UNION
SELECT
"queries_reservedname"."name",
"queries_reservedname"."id"
FROM
"queries_reservedname"
ORDER BY
(2) ASC
LIMIT
1
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32627>
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/053.59938cd39d8d44f506cc8df32f1ba0ae%40djangoproject.com.