Thanks to visit codestin.com
Credit goes to github.com

Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

PageNumberPagination.get_page_number returns 1 when page_query_param == 0 #9533

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

Closed
dishn opened this issue Sep 12, 2024 · 0 comments
Closed

Comments

@dishn
Copy link

dishn commented Sep 12, 2024

version 3.15.2
python 3.10.14

Not sure if this is expected behavior, but when page_query_param == 0, the page_number variable sets to 1 in get_page_number:

    def get_page_number(self, request, paginator):
        page_number = request.query_params.get(self.page_query_param) or 1
        if page_number in self.last_page_strings:
            page_number = paginator.num_pages
        return page_number

where:

>>> page_number = request.query_params.get(self.page_query_param) or 1
>>> page_number = 0 or 1
>>> page_number = 1

I believe the original intention is to check empty string not value 0: #8578

I would consider the get_page_number function to allow value 0:

    def get_page_number(self, request, paginator):
        """
        Overrides the get_page_number method to handle case where page=0
        """
        param_numer = request.query_params.get(self.page_query_param)
        return 0 if param_numer == 0 else super().get_page_number(request, paginator)
@encode encode locked and limited conversation to collaborators Sep 12, 2024
@tomchristie tomchristie converted this issue into discussion #9534 Sep 12, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant