pagination.LimitOffsetPagination.get_html_context fails when count=0 and offset=0 · Issue #3303 · encode/django-rest-framework (original) (raw)
For 3.2.2
In LimitOffsetPagination.get_html_context method, when offset value is zero, current is 1 (bacause _divide_with_ceil function always returns 0 when first param is 0)
current = _divide_with_ceil(self.offset, self.limit) + 1
and when count is zero too (it means there is no object in our data, model etc.),
final = (
_divide_with_ceil(self.count - self.offset, self.limit) +
_divide_with_ceil(self.offset, self.limit)
)
final computed as 0 (zero) because 'self.count - self.offset = self.offset = 0'
And finally,
if current > final:
current = final
current = final = 0 .
Then _get_displayed_page_numbers function raises assertion error on here:
https://github.com/tomchristie/django-rest-framework/blob/1b53e804ee86e5611bb02ced499e1fcc08b6c5f9/rest_framework/pagination.py#L75
assert current >= 1
assert final >= current
Am I doing wrong anything or is it just a bug?