Invalid page numbers get treated as '1'

Signed-off-by: Paul Wayper <paulway@redhat.com>
This commit is contained in:
Paul Wayper 2020-11-06 08:31:29 +11:00
parent 225bc3a762
commit 3922b97380

View File

@ -265,8 +265,12 @@ class PageNumberPagination(BasePagination):
return self.page_size return self.page_size
def get_page_number(self, request): def get_page_number(self, request):
# This can be negative to mean 'pages from the end'. # This can be negative to mean 'pages from the end'. Invalid values
# are ignored, and the default is page 1.
try:
return int(request.query_params.get(self.page_query_param, 1)) return int(request.query_params.get(self.page_query_param, 1))
except ValueError:
return 1
def get_next_link(self): def get_next_link(self):
if not self.page.has_next(): if not self.page.has_next():