Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pagination.LimitOffsetPagination.get_html_context fails when count=0 and offset=0 #3303

Closed
ugurunver opened this issue Aug 19, 2015 · 0 comments
Labels
Milestone

Comments

@ugurunver
Copy link

For 3.2.2

https://github.com/tomchristie/django-rest-framework/blob/1b53e804ee86e5611bb02ced499e1fcc08b6c5f9/rest_framework/pagination.py#L414

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?

ugurunver added a commit to ugurunver/django-rest-framework that referenced this issue Aug 19, 2015
@tomchristie tomchristie added this to the 3.2.3 Release milestone Aug 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants