Missing ORDER BY in subselect?

13 views
Skip to first unread message

Gregor Jerše

unread,
Apr 16, 2014, 3:16:02 PM4/16/14
to django...@googlegroups.com
Hi!

I am experiencing a weird Queryset behavior. Let the variable treatments refer
to an ordered (and sliced) queryset. The first query

Service.objects.filter(treatment__in=treatments).distinct()

returns different objects than the second one

Service.objects.filter(treatment__in=list(treatments)).distinct()

, but I would expect both results to be the same. Service model declares
treatment field as ForeignKey.

The results given by the first query are incorrect. Further SQL code
inspection reveals that ORDER BY clause (from treatments QuerySet) is missing
in subselect.

The results of the second query are correct, since subquery is evaluated first
(with ORDER BY clause included).

It actually looks similar to an old bug #12328, which was marked as fixed long
time ago and I am using Django 1.6. Am I missing something?

Many Thanks,
Gregor

Simon Charette

unread,
Apr 16, 2014, 5:09:29 PM4/16/14
to django...@googlegroups.com, gre...@jerse.info
I pretty sure this is related to #22434.

There's a patch on Github I'm actually reviewing and it's looking pretty good.

If all goes well it should make it to Django 1.7.
Reply all
Reply to author
Forward
0 new messages