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

Improve #1084 to run rate limited error retry handler correctly #1094

Merged
merged 1 commit into from
Aug 17, 2021

Conversation

seratch
Copy link
Member

@seratch seratch commented Aug 17, 2021

Summary

This pull request fixes a few bugs in #1084 about the built-in rate limited error handlers (sync/async)

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs-src (Documents, have you run ./docs.sh?)
  • /docs-src-v2 (Documents, have you run ./docs-v2.sh?)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements (place an x in each [ ])

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

@@ -70,7 +70,7 @@ async def prepare_for_next_attempt_async(
if response is None:
raise error

state.increment_current_attempt()
state.next_attempt_requested = True
Copy link
Member Author

Choose a reason for hiding this comment

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

This should exist here but it was missing in this method (this bug affects only RateLimitedErrorRetryHandler)

@@ -39,6 +39,10 @@ def _can_retry(
if error is None:
return False

if isinstance(error, URLError):
Copy link
Member Author

Choose a reason for hiding this comment

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

As HttpError is a sub-class of URLError, we should have checked if the response exists here.

@@ -69,7 +73,7 @@ def prepare_for_next_attempt(
if response is None:
raise error

state.increment_current_attempt()
state.next_attempt_requested = True
Copy link
Member Author

Choose a reason for hiding this comment

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

This should exist here but it was missing in this method (this bug affects only RateLimitedErrorRetryHandler)

headers: Dict[str, Union[str, List[str]]],
body: Optional[Dict[str, Any]] = None,
data: Optional[bytes] = None,
):
self.status_code = status_code
self.status_code = int(status_code)
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated to the bug we are fixing here; Just to make this a bit more robust

@@ -143,6 +143,15 @@ def convert_params(values: dict) -> dict:
res,
)

if logger.level <= logging.DEBUG:
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this debug logging from slack_response.py

@@ -522,10 +522,24 @@ def _perform_urllib_http_request_internal(
if resp.headers.get_content_type() == "application/gzip":
# admin.analytics.getFile
body: bytes = resp.read()
if self._logger.level <= logging.DEBUG:
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this debug logging from slack_response.py

@@ -186,14 +186,6 @@ def validate(self):
Raises:
SlackApiError: The request to the Slack API failed.
"""
if self._logger.level <= logging.DEBUG:
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this logging from here to base client classes to print this even for the retry patterns

@codecov
Copy link

codecov bot commented Aug 17, 2021

Codecov Report

Merging #1094 (58b34ef) into main (f3f2adb) will increase coverage by 0.11%.
The diff coverage is 86.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1094      +/-   ##
==========================================
+ Coverage   86.06%   86.17%   +0.11%     
==========================================
  Files         110      110              
  Lines        9936     9945       +9     
==========================================
+ Hits         8551     8570      +19     
+ Misses       1385     1375      -10     
Impacted Files Coverage Δ
slack_sdk/web/slack_response.py 92.85% <ø> (-0.37%) ⬇️
slack_sdk/web/base_client.py 88.93% <50.00%> (-0.63%) ⬇️
slack_sdk/http_retry/builtin_async_handlers.py 95.12% <100.00%> (+0.12%) ⬆️
slack_sdk/http_retry/builtin_handlers.py 92.85% <100.00%> (+32.33%) ⬆️
slack_sdk/http_retry/response.py 100.00% <100.00%> (ø)
slack_sdk/web/async_internal_utils.py 82.35% <100.00%> (+0.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3f2adb...58b34ef. Read the comment docs.

@seratch seratch merged commit 9cab809 into slackapi:main Aug 17, 2021
@seratch seratch deleted the pr-1084-fix-rate-limit-retries branch August 17, 2021 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant