mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge f91d332c6c
into 003c304115
This commit is contained in:
commit
d4df1b8094
|
@ -572,7 +572,7 @@ class CursorPagination(BasePagination):
|
|||
if not self.has_next:
|
||||
return None
|
||||
|
||||
if self.cursor and self.cursor.reverse and self.cursor.offset != 0:
|
||||
if self.cursor and self.cursor.reverse and self.cursor.offset != 0 and self.page:
|
||||
# If we're reversing direction and we have an offset cursor
|
||||
# then we cannot use the first position we find as a marker.
|
||||
compare = self._get_position_from_instance(self.page[-1], self.ordering)
|
||||
|
@ -620,7 +620,7 @@ class CursorPagination(BasePagination):
|
|||
if not self.has_previous:
|
||||
return None
|
||||
|
||||
if self.cursor and not self.cursor.reverse and self.cursor.offset != 0:
|
||||
if self.cursor and not self.cursor.reverse and self.cursor.offset != 0 and self.page:
|
||||
# If we're reversing direction and we have an offset cursor
|
||||
# then we cannot use the first position we find as a marker.
|
||||
compare = self._get_position_from_instance(self.page[0], self.ordering)
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.test import TestCase
|
|||
from rest_framework import (
|
||||
exceptions, filters, generics, pagination, serializers, status
|
||||
)
|
||||
from rest_framework.pagination import PAGE_BREAK, PageLink
|
||||
from rest_framework.pagination import PAGE_BREAK, PageLink, Cursor
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.test import APIRequestFactory
|
||||
|
||||
|
@ -633,6 +633,16 @@ class CursorPaginationTestsMixin:
|
|||
|
||||
assert isinstance(self.pagination.to_html(), type(''))
|
||||
|
||||
def test_offset_cutoff(self):
|
||||
(previous, current, next, previous_url, next_url) = self.get_pages('/')
|
||||
|
||||
next_url = self.pagination.encode_cursor(Cursor(1050, False, None))
|
||||
(previous, current, next, previous_url, next_url) = self.get_pages(next_url)
|
||||
|
||||
assert previous == [7, 7, 7, 8, 9]
|
||||
assert current == []
|
||||
assert next is None
|
||||
|
||||
|
||||
class TestCursorPagination(CursorPaginationTestsMixin):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user