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

Add MAX_PAGE_SIZE setting #9107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TheSuperiorStanislav
Copy link
Contributor

@TheSuperiorStanislav TheSuperiorStanislav commented Sep 14, 2023

Description

Add a setting for max page size for global pagination. Our team discovered that by default, page size is unlimited which could lead to API abuse and the only way to fix it -> it's to subclass pagination class(which is a working solution, but not convenient). After investigating issues I found related issue and comment.

@auvipy auvipy self-requested a review September 14, 2023 14:11
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this deserve a test case,, but as it is adding/exposing new API surface to the framework, we might need to pass the design decision step first

@auvipy
Copy link
Member

auvipy commented Sep 14, 2023

OK I saw the comment now #6185 (comment) it might be possible in class level but not globally at the moment.

@auvipy auvipy added this to the 3.15 milestone Sep 14, 2023
@TheSuperiorStanislav
Copy link
Contributor Author

@auvipy I added tests for system checks, but didn't managed to find and add tests for settings with API requests like in test_pagination.py, and it's kind hard to add since pagination settings are defined as class attrs.

Co-authored-by: Roman Gorbil <roman.gorbil@saritasa.com>
@auvipy
Copy link
Member

auvipy commented Oct 2, 2023

we got a PR related to this area #8993. would be helpful if you review and share your views on the PR.

max_page_size = None
# Defaults to `None`, meaning page size is unlimited.
# It's recommended that you would set a limit to avoid api abuse.
max_page_size = api_settings.MAX_PAGE_SIZE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #8993, I think this should be a property to allow the setting be overriden in Django tests after the views were created.

@@ -383,7 +385,7 @@ class LimitOffsetPagination(BasePagination):
limit_query_description = _('Number of results to return per page.')
offset_query_param = 'offset'
offset_query_description = _('The initial index from which to return the results.')
max_limit = None
max_limit = api_settings.MAX_PAGE_SIZE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I think this shoud be a property.

@@ -601,7 +603,7 @@ class CursorPagination(BasePagination):

# Set to an integer to limit the maximum page size the client may request.
# Only relevant if 'page_size_query_param' has also been set.
max_page_size = None
max_page_size = api_settings.MAX_PAGE_SIZE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I think this shoud be a property.

@ankitchhatbar
Copy link

ankitchhatbar commented Dec 22, 2023

@auvipy @christophehenry @TheSuperiorStanislav If you don't mind, I can take this up and implement the changes requested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants