Opened 16 years ago
Closed 15 years ago
#11283 closed Bug (fixed)
latest() doesn't clear previous ordering
| Reported by: | benmoran | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Unlike order_by() in django.db.models.query, the latest() method doesn't clear previous orderings.
This means that latest can return incorrect results if used on a previously sorted QuerySet, e.g.
Article.objects.order_by('id').latest('id')
returns the first rather than the last id.
It looks strange when written on a single line, but can happen - I encountered it with code from django-reversion using QuerySets that already had orderings set.
Attachments (5)
Change History (12)
by , 16 years ago
by , 16 years ago
| Attachment: | latest-clear-ordering.patch added |
|---|
comment:1 by , 16 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 16 years ago
| Needs tests: | set |
|---|---|
| Version: | 1.0 |
by , 16 years ago
| Attachment: | query_latest_ordering.diff added |
|---|
comment:4 by , 15 years ago
Same patch updated for current trunk. Please test and move to ready for checkin if it works for you too.
by , 15 years ago
| Attachment: | 11283.diff added |
|---|
comment:5 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → Bug |
by , 15 years ago
| Attachment: | 11283.latest-clear-ordering.diff added |
|---|
comment:6 by , 15 years ago
| Easy pickings: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
Thank you for the patch. I've just added a reference to this ticket number in the test's comment for posterity.
adding a test to the patch