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

Ability to modify the pagination limit on a per-resource basis #1498

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions eve/tests/methods/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ def test_get_max_results(self):
resource = response["_items"]
self.assertEqual(len(resource), self.app.config["PAGINATION_LIMIT"])

def test_get_max_results_overridden(self):
# Generate 50 contacts.
self.random_contacts(num=50)

# Set the max pagination limit to 7.
self.app.config["DOMAIN"][self.known_resource]["pagination_limit"] = 7

# Attempt to get all 50 contacts in one request.
response, status = self.get(self.known_resource, "?max_results=50")
self.assert200(status)

# Validate that the response only contains 10 contacts.
resource = response["_items"]
self.assertEqual(len(resource), 7)

def test_get_custom_max_results(self):
self.app.config["QUERY_MAX_RESULTS"] = "size"
maxr = 10
Expand Down
6 changes: 4 additions & 2 deletions eve/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ def parse_request(resource):

# TODO should probably return a 400 if 'max_results' < 1 or
# non-numeric
if r.max_results > config.PAGINATION_LIMIT:
r.max_results = config.PAGINATION_LIMIT
# Fetch the custom pagination limit from the schema, default to the global one.
pagination_limit = settings.get("pagination_limit") or config.PAGINATION_LIMIT
if r.max_results > pagination_limit:
r.max_results = pagination_limit

def etag_parse(challenge):
if challenge in headers:
Expand Down