From 22631c73a71e7ca1b5d32c9bf45e4b732e514c7f Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 23 Jul 2015 12:41:35 +0100 Subject: [PATCH] Resolve assertion error with LimitOffsetPagination and erronous parameters. Closes #2920. --- rest_framework/pagination.py | 2 ++ tests/test_pagination.py | 6 ++++++ 2 files changed, 8 insertions(+) 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.