From 84c8416f54466b95a54ea88ff3628a3de251d88f Mon Sep 17 00:00:00 2001 From: Pieter De Clercq Date: Thu, 9 Mar 2023 19:04:02 +0100 Subject: [PATCH 1/2] Add test --- eve/tests/methods/get.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/eve/tests/methods/get.py b/eve/tests/methods/get.py index 0fdac0f39..87eda7401 100644 --- a/eve/tests/methods/get.py +++ b/eve/tests/methods/get.py @@ -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 From a3951ffe5b2fb28e26b4b1929b17980370483994 Mon Sep 17 00:00:00 2001 From: Pieter De Clercq Date: Thu, 9 Mar 2023 19:18:48 +0100 Subject: [PATCH 2/2] Implement feature --- eve/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eve/utils.py b/eve/utils.py index 384a74dc1..b0a0e249d 100644 --- a/eve/utils.py +++ b/eve/utils.py @@ -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: