﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22550	QuerySet last() and reverse() confusing when used with ordered slices	Jon Dufresne	Michael Käufl	"I ran all tests below with MySQL backend. 

Given the following model:

{{{
class MyModel(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        ordering = ['name']

    def __unicode__(self):
        return self.name
}}}

From the following test script I receive the output:

{{{
import os
os.environ.setdefault(""DJANGO_SETTINGS_MODULE"", ""djtest.settings"")
from myapp.models import MyModel

MyModel.objects.all().delete()
for i in range(10):
    m = MyModel(name='model%d' % i)
    m.save()

print MyModel.objects.all()[0:5]
print MyModel.objects.all()[0:5].last()
print MyModel.objects.all()[0:5].reverse()
}}}

{{{
[<MyModel: model0>, <MyModel: model1>, <MyModel: model2>, <MyModel: model3>, <MyModel: model4>]
model9
[<MyModel: model9>, <MyModel: model8>, <MyModel: model7>, <MyModel: model6>, <MyModel: model5>, <MyModel: model4>, <MyModel: model3>, <MyModel: model2>, <MyModel: model1>, <MyModel: model0>]
}}}

In my opinion, the lines that show the output of {{{last()}}} and {{{reverse()}}} are confusing. My naive expectation was that each of these would be operating on the slice. That is, the last value from the slice or the reverse order of the slice. 

{{{
model4
[<MyModel: model4>, <MyModel: model3>, ...
}}}

Of course, after thinking about how this might get translated to SQL I understand why this happens. Making this a leaky abstraction. In my opinion, if expected behavior can't be realized an exception preventing the operation makes more sense.

The original reason I bumped into this is I was creating a custom Paginator to create page labels based on the first and last item on the page. As Paginator uses slices, calling {{{last()}}} produced unexpected (to me) results.
"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
