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

handle bad batching input as a BadRequest #1856

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 11 additions & 6 deletions src/plone/restapi/batching.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from plone.batching.batch import Batch
from plone.restapi.deserializer import json_body
from plone.restapi.exceptions import DeserializationError
from zExceptions import BadRequest
from urllib.parse import parse_qsl
from urllib.parse import urlencode

Expand All @@ -11,12 +13,15 @@ class HypermediaBatch:
def __init__(self, request, results):
self.request = request

self.b_start = int(json_body(self.request).get("b_start", False)) or int(
self.request.form.get("b_start", 0)
)
self.b_size = int(json_body(self.request).get("b_size", False)) or int(
self.request.form.get("b_size", DEFAULT_BATCH_SIZE)
)
try:
self.b_start = int(json_body(self.request).get("b_start", False)) or int(
self.request.form.get("b_start", 0)
)
self.b_size = int(json_body(self.request).get("b_size", False)) or int(
self.request.form.get("b_size", DEFAULT_BATCH_SIZE)
)
except (ValueError, DeserializationError) as e:
raise BadRequest(e)
Copy link
Member

Choose a reason for hiding this comment

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

Could you write a test for this case please?


self.batch = Batch(results, self.b_size, self.b_start)

Expand Down
Loading