LimitOffset pagination crashes Browseable API when limit=0 · Issue #4079 · encode/django-rest-framework (original) (raw)
We are using LimitOffsetPagination
on all our endpoints, and noticed that sending limit=0
to the browsable api causes a crash. Getting json
output (either from an xmlhttprequest or from format=json
) does not crash.
Steps to reproduce
- Install
LimitOffsetPagination
as the default pagination - Open a
list
(ours areModelViewSet
) in the browser - Set the query string to
?limit=0&offset=20
- boom
Notes
We use a custom LimitOffset pagination, which just overrides the max and default limit
Using DRF 3.3.2
Expected behavior
Should show the browsable api for the endpoint, with the following data:
{
"count":148,
"next":"https://api.co/page/?limit=0&offset=20",
"previous":"https://api.co/page/?limit=0&offset=20",
"results":[]
}
Actual behavior
Exception Type: ZeroDivisionError
Exception Value:
integer division or modulo by zero
Exception Location: .../venv/local/lib/python2.7/site-packages/rest_framework/pagination.py in _divide_with_ceil, line 41
Python Executable: /usr/local/bin/uwsgi
.../venv/local/lib/python2.7/site-packages/rest_framework/pagination.py in get_html_context
current = _divide_with_ceil(self.offset, self.limit) + 1 ...
▼ Local vars
self <mysite.LargePageination object at 0x7f614e677bd0>
base_url 'https://api.co/page/?limit=0&offset=20'
.../venv/local/lib/python2.7/site-packages/rest_framework/pagination.py in _divide_with_ceil
if a % b: ...
▼ Local vars
a 20
b 0