diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index d8793f693..7fe8559c5 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -540,7 +540,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) @@ -588,7 +588,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)