Opened 10 years ago
Closed 10 years ago
#22923 closed Bug (duplicate)
order_by clause missing on nested queryset
Reported by: | Grant Jenks | 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
The ORDER BY clause is getting dropped on a nested queryset with the sqlite3 database backend.
Repro steps:
models.py
from django.db import models class Report(models.Model): modify_time = models.DateTimeField(auto_now=True) uuid = models.CharField(max_length=36, unique=True) deleted = models.BooleanField(default=False) class Measure(models.Model): report = models.ForeignKey(Report, db_column='report_uuid', to_field='uuid', on_delete=models.CASCADE)
python manage.py shell
In [1]: from testtest.models import Report, Measure In [2]: reports = Report.objects.filter(deleted=False).order_by('-modify_time')[:5] In [3]: print reports.query SELECT "deleteme_report"."id", "deleteme_report"."modify_time", "deleteme_report"."uuid", "deleteme_report"."deleted" FROM "deleteme_report" WHERE "deleteme_report"."deleted" = False ORDER BY "deleteme_report"."modify_time" DESC LIMIT 5 In [4]: measures = Measure.objects.filter(report__in=reports) In [5]: print measures.query SELECT "deleteme_measure"."id", "deleteme_measure"."report_uuid" FROM "deleteme_measure" WHERE "deleteme_measure"."report_uuid" IN (SELECT "deleteme_report"."uuid" FROM "deleteme_report" WHERE "deleteme_report"."deleted" = False LIMIT 5)
Note that reports.query includes the ORDER BY clause but when nested in measures.query, it is missing.
settings.py is stock from django-admin.py in v1.6 on CPython 2.7.
Change History (2)
comment:1 by , 10 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|
comment:2 by , 10 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I think this is a duplicate of #22434 which has been fixed in 1.7.x
Note:
See TracTickets
for help on using tickets.
Just tested with 1.7rc1 and this doesn't seem to be an issue:
Does anyone know what changed might've fixed this?