#23259: Query extra() select_params are inserted in the incorrect order in the
overall query parameters with values_list
----------------------------------------------+----------------------
Reporter: rajivm | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.7-rc-2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+----------------------
This is running the latest stable/1.7
(267630ad50c69ebfe594de37a0636264aa5be7d6)
{{{
User.objects.extra(select=OrderedDict([('points', 'id + %s')]),
select_params=[5]).filter(id__gte=3).extra(order_by=['points']).values_list("id",
flat=True)
}}}
{{{
[DEBUG django.db.backends] (0.001) SELECT "auth_user"."id" FROM
"auth_user" WHERE "auth_user"."id" >= 5 ORDER BY (id + 3) ASC LIMIT 21;
args=(5, 3)
}}}
Whereas in Django 1.6 (the correct query):
{{{
[DEBUG django.db.backends] (0.003) SELECT "auth_user"."id", (id + 5) AS
"points" FROM "auth_user" WHERE "auth_user"."id" >= 3 ORDER BY "points"
ASC LIMIT 21; args=(5, 3)
}}}
In the second case, the extra select_param of 5 is correctly matched with
the extra select "id + %s", resulting in id+5.
However, in the first case, in Django 1.7, the extra select results in id
+ 3 (incorrectly inverting the parameters to the query).
It seems like what is happening is the "select" of "points" (the extra
select) is being optimized out because of the values_list, but is being
kept by the extra(order_by) -- resulting in it being in a different part
of the query.
I tried to simplify the example as much as possible (I had a much crazier
query this was destroying).
Let me know if you have any questions.
--
Ticket URL: <https://code.djangoproject.com/ticket/23259>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.65847aa099af5caaf480b67af959d8b2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.