I can confirm this issue on Django 1.11.15 (Python 3.4.3, MySQL 5.5.61). 
Calling 'last()' on a slice produces wrong result:

>>> News.objects.all().order_by('id')[:5].values('id')
<QuerySet [{'id': 1}, {'id': 2}, {'id': 3}, {'id': 4}, {'id': 5}]>

>>> News.objects.all().order_by('id')[:5][4].id
5

>>> #But calling 'last' gives us wrong id:
>>> News.objects.all().order_by('id')[:5].last()
11


понедельник, 24 сентября 2018 г., 13:49:08 UTC+2 пользователь Shivam Jindal 
написал:
>
> Hi,
>
> I am making a queryset by slicing it to return only first 2 objects but 
> When I am using .last() on this queryset then it is not applying slicing
>
> Pharmaceutical.objects.order_by('id').values('id')
> >>> [{'id': 2L}, {'id': 3L}, {'id': 4L}, {'id': 5L}]
>
> >>> Pharmaceutical.objects.order_by('id')[:2].values('id')
> [{'id': 2L}, {'id': 3L}]
>
> >>> Pharmaceutical.objects.order_by('id')[:2].values('id').last()
> {'id': 5L} # But this should be 3
>
> -- 
> Thanks,
>
> Regards
> Shivam Jindal
> +91 8586896112
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/d2a29c84-00f8-41e9-85fa-a8bf20985218%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to