[Django] #28775: Queryset last() does not honor slices

6 views
Skip to first unread message

Django

unread,
Nov 6, 2017, 1:06:34 PM11/6/17
to django-...@googlegroups.com
#28775: Queryset last() does not honor slices
-------------------------------------+-------------------------------------
Reporter: Liquid | Owner: nobody
Scorpio |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28775>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 7, 2017, 9:21:14 AM11/7/17
to django-...@googlegroups.com
#28775: Queryset last() does not honor slices
-------------------------------------+-------------------------------------
Reporter: Liquid Scorpio | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jon Dufresne):

* status: new => closed
* resolution: => duplicate


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28775#comment:1>

Reply all
Reply to author
Forward
0 new messages