Opened 8 years ago
Closed 8 years ago
#28775 closed Bug (duplicate)
Queryset last() does not honor slices
| Reported by: | Liquid Scorpio | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.11 |
| 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
Assume there is a time series of records for 100 days.
MyModel.objects.all().order_by('-date').last()
Returns the oldest record in the time series, which is same as returned by:
MyModel.objects.all().order_by('-date')[:10].last()
This is not intuitive. Should return the 10th newest record, the slice operator [:10] should be honoured.
Note:
See TracTickets
for help on using tickets.
I believe this is a duplicate of #22550. In Django 2.0, this will throw a
TypeError. See, https://docs.djangoproject.com/en/dev/releases/2.0/#queryset-reverse-and-last-are-prohibited-after-slicing.