diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index a171c684f..762ce58c2 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -419,6 +419,8 @@ class LimitOffsetPagination(BasePagination): _divide_with_ceil(self.count - self.offset, self.limit) + _divide_with_ceil(self.offset, self.limit) ) + if current > final: + current = final def page_number_to_url(page_number): if page_number == 1: diff --git a/tests/test_pagination.py b/tests/test_pagination.py index 03c4fdf47..63fdbecae 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py @@ -435,6 +435,12 @@ class TestLimitOffset: ] } + def test_erronous_offset(self): + request = Request(factory.get('/', {'limit': 5, 'offset': 1000})) + queryset = self.paginate_queryset(request) + self.get_paginated_content(queryset) + self.get_html_context() + def test_invalid_offset(self): """ An invalid offset query param should be treated as 0.