Wednesday, April 16, 2014

Missing ORDER BY in subselect?

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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4696202.A3ANhoRLR9%40gregor.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment