Opened 9 years ago

Closed 9 years ago

#25272 closed Bug (wontfix)

Query doesn't include `ORDER BY` statement in subquery

Reported by: Aykut Özat Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I faced this in Django 1.6.x. Please notice ORDER BY is not included in subquery.

In [1]: profiles=UserProfile.objects.order_by('pk')[:10]

In [2]: print User.objects.filter(userprofile__in=profiles).query
SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" INNER JOIN "accounts_userprofile" ON ( "auth_user"."id" = "accounts_userprofile"."user_id" ) WHERE "accounts_userprofile"."id" IN (SELECT "accounts_userprofile"."id" FROM "accounts_userprofile" LIMIT 10)

I also tried this same case on a project running Django 1.8.3, the printed query was correct as expected.

Change History (3)

comment:1 by Tim Graham, 9 years ago

Per our supported versions policy, 1.6 is no longer receiving security or bug fixes. Are you saying the issue is fixed in Django 1.8?

comment:2 by Aykut Özat, 9 years ago

It is fixed in both 1.7 and 1.8. I've tried it on 1.7 too.

comment:3 by Aykut Özat, 9 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top