-
Notifications
You must be signed in to change notification settings - Fork 215
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
fix: Fix JSON response validation retry strategy #831
Conversation
Pull Request Test Coverage Report for Build 5718880988
💛 - Coveralls |
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.
Pls apply comments
boxsdk/session/session.py
Outdated
:param request: | ||
The API request that could be unsuccessful. | ||
""" | ||
if request.expect_json_response and not is_json_response(network_response): |
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.
could be simplified to simple return statement.
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.
if function return bool it is a good practice to name functions strating from is_...
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.
maybe _is_json_response_if_expected, or sth like this
boxsdk/session/session.py
Outdated
@@ -398,6 +413,10 @@ def _get_retry_request_callable( | |||
self._send_request, | |||
) | |||
code = network_response.status_code | |||
|
|||
if request.method == 'GET' and network_response and network_response.ok and not self._validate_json_response(network_response, request): |
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.
Why request.method == 'GET'
when makin Post which return json it can also happen
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.
and network_response
is it necessary ? if network_response is None:
case is handled above
boxsdk/session/session.py
Outdated
@@ -398,6 +413,10 @@ def _get_retry_request_callable( | |||
self._send_request, | |||
) | |||
code = network_response.status_code | |||
|
|||
if request.method == 'GET' and network_response and network_response.ok and not self._validate_json_response(network_response, request): | |||
return self._send_request |
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.
Partial should be used to apply exponential backoff logic
test/unit/session/test_session.py
Outdated
|
||
def test_box_session_raises_for_non_json_response_after_retry(box_session, mock_network_layer, non_json_response, test_url): | ||
# pylint:disable=redefined-outer-name | ||
API.MAX_RETRY_ATTEMPTS = 1 |
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.
NO need to modufy this variable at all now!
No description provided.