-
Notifications
You must be signed in to change notification settings - Fork 20
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
Support parsing batch results #146
Conversation
Support parsing results from batch requests with a parse_results method and a results attribute on a Batch context client after the batch operation is sent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly wording :)
Thanks !!!
CHANGELOG.rst
Outdated
@@ -7,7 +7,7 @@ This document describes changes between each past release. | |||
8.1.0 (unreleased) | |||
================== | |||
|
|||
- Nothing changed yet. | |||
- Allow reading from batch contexts using the ``parse_results`` method. (#146) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to be more human friendly with something like:
Allow reading responses from batch requests with the ``results()`` method. (#146)
README.rst
Outdated
batch.update_record(data={'id': idx}) | ||
|
||
A batch object shares the same methods as another client. | ||
Reading data from batch operations is achived by using the ``parse_results`` method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when mentionning a method, it's nicer if we put the parenthesis ()
kinto_http/batch.py
Outdated
self.results.append((resp, headers)) | ||
return self.results | ||
|
||
def parse_results(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
results()
should be enough IMO. Parsing is not truely the action here
kinto_http/batch.py
Outdated
|
||
def parse_results(self): | ||
# Get each batch block response | ||
block_responses = [resp for resp, _ in self.results] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chunks
would be easier to understand since we use this term previously
kinto_http/tests/test_batch.py
Outdated
@@ -112,3 +112,25 @@ def test_batch_raises_exception_as_soon_as_subrequest_fails(self): | |||
with self.assertRaises(KintoException): | |||
batch.send() | |||
assert self.client.session.request.call_count == 1 | |||
|
|||
def test_results_attribute_is_available(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we have both. Especially because this results
attributes is chunked. I know we'd lose the headers information, but I would rather make it private. Especially if we don't make it official in docs.
I am not crazy about the API because it seems forwards-incompatible for doing things like sending a batch of updates as part of an offline-first sync() call. I get that simple things should be simple, but this makes complicated things a little harder. But we can always just break compatibility later.. |
56584b1
to
f46a1e6
Compare
f46a1e6
to
ae732c5
Compare
I agree this API is limited, but honestly I think we should support both a simple way to fetch only the response body and another to fetch the full response (mostly for internal stuff). I can't see a way to have an easy to use and fully forward-compatible call, do you have something in mind? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits left, but then I'm ok to merge :)
README.rst
Outdated
batch.get_record('r2') | ||
batch.get_record('r3') | ||
|
||
r1, r2, r3 = batch.parse_results() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover :)
README.rst
Outdated
batch.update_record(data={'id': idx}) | ||
|
||
A batch object shares the same methods as another client. | ||
Reading data from batch operations is achived by using the ``results()`` method | ||
available ater a batch context is closed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
achieved
after
README.rst
Outdated
|
||
r1, r2, r3 = batch.parse_results() | ||
|
||
Besides the ``parse_results`` method, a batch object shares all the same methods as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover
kinto_http/__init__.py
Outdated
@@ -97,6 +97,10 @@ def batch(self, **kwargs): | |||
batch_session = BatchSession(self, | |||
batch_max_requests=batch_max_requests) | |||
batch_client = self.clone(session=batch_session, **kwargs) | |||
|
|||
# set a reference for reading results from the context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
µnit: capitalize first word and add trailing .
@@ -43,7 +44,6 @@ def _build_requests(self): | |||
return requests | |||
|
|||
def send(self): | |||
result = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we want to reset self._results
here?
Side note: dont code in a hurry...
What I would normally do is return a Response object which has a |
Fixes/Updates #145
This may not be the best API for this feature, but it does support the use case for dumping records on kinto-wizard (Kinto/kinto-wizard#16).
A small example:
Todos:
Opinions?