Page size limits and opt-in pagination behavior in Django REST Framework
0 reputation · 29 Mar 2022, 13:26 UTC
Django REST Framework list actions return the full queryset by default. Pagination is opt-in and must be configured on a view or via REST_FRAMEWORK settings. This leaves the decision to enable pagination and choose defaults to the project author.
When PageNumberPagination is used, client-controlled page size is only possible if page_size_query_param is set, and an upper bound is only enforced if max_page_size is configured. Both options require explicit developer enablement.
LimitOffsetPagination provides offset based paging, but without max_limit set there is no built-in hard cap on the limit value a client can request. The framework intentionally does not enforce a default pagination policy, which creates an unresolved trade-off between convenience for small APIs and safety for large datasets.
What is the default enforcement behavior for max_page_size when page_size_query_param is enabled on PageNumberPagination? How does LimitOffsetPagination behave with an unbounded limit parameter when max_limit is not set? Is there a documented project-level default recommendation for pagination to balance convenience and query safety?