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

fix: Fix JSON response validation retry strategy #831

Merged
merged 11 commits into from
Aug 1, 2023
Merged

Conversation

congminh1254
Copy link
Member

No description provided.

@congminh1254 congminh1254 changed the title fix: Fix non-json retryable fix: Fix json validation retry strategy Jul 27, 2023
@congminh1254 congminh1254 changed the title fix: Fix json validation retry strategy fix: Fix JSON response validation retry strategy Jul 27, 2023
@congminh1254 congminh1254 marked this pull request as draft July 27, 2023 09:11
@coveralls
Copy link

coveralls commented Jul 27, 2023

Pull Request Test Coverage Report for Build 5718880988

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 93.525%

Totals Coverage Status
Change from base Build 5655911124: 0.005%
Covered Lines: 3452
Relevant Lines: 3691

💛 - Coveralls

@congminh1254 congminh1254 marked this pull request as ready for review July 27, 2023 13:17
Copy link
Contributor

@lukaszsocha2 lukaszsocha2 left a comment

Choose a reason for hiding this comment

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

Pls apply comments

:param request:
The API request that could be unsuccessful.
"""
if request.expect_json_response and not is_json_response(network_response):
Copy link
Contributor

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.

Copy link
Contributor

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_...

Copy link
Contributor

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

@@ -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):
Copy link
Contributor

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

Copy link
Contributor

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

@@ -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
Copy link
Contributor

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


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
Copy link
Contributor

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!

@congminh1254 congminh1254 merged commit 69834eb into main Aug 1, 2023
11 checks passed
@congminh1254 congminh1254 deleted the fix-non-json branch August 1, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants