Repository navigation
fix: return the last response when async retries run out - #2088
Conversation
After 100 response-driven retries the async web, webhook, SCIM, and audit logs clients raised `None`, a TypeError, because they only kept the response they were about to return. They now keep the last one, as the sync clients do. SCIM and audit logs build it lazily since their response classes parse the body. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2088 +/- ##
==========================================
+ Coverage 84.79% 84.84% +0.04%
==========================================
Files 118 118
Lines 14129 14136 +7
==========================================
+ Hits 11981 11994 +13
+ Misses 2148 2142 -6 ☔ View full report in Codecov by Harness. |
…tries
A retried 429 with a malformed `{` body now has a test in each client, so
building the response eagerly again would fail it: the handlers would retry
the parse error for the same attempt and send one request fewer.
Also drop the `resp` declaration and the `return resp` after `finally`,
which can't be reached now that `resp` is only set right before the
in-loop return.
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
WilliamBergamin
left a comment
There was a problem hiding this comment.
🚦 No breaking changes here: only the private retry helpers change, and the async clients now end their retries the way the sync clients already do. The new tests fail on main with the TypeError and pass here.
Left two optional comments, nothing blocking 💯
| self.assertEqual([500], error_statuses(retry_handler.prepare_errors)) | ||
|
|
||
| @async_test | ||
| async def test_ratelimited_returns_the_last_response_when_retries_run_out(self): |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): Could we add a retried 429 with a malformed { body for audit logs and SCIM? Nothing pins why the response is built lazily, so a later eager build would re-run the retry handlers with a JSONDecodeError and no test would catch it.
cchensh
left a comment
There was a problem hiding this comment.
LGTM. I confirmed the four new tests fail on main with the TypeError and pass here. A few non-blocking nits:
slack_sdk/webhook/async_client.py: thereturn respafterfinallyat the end of_perform_http_requestis still unreachable. It was removed from SCIM and audit logs but not here.- A saved response now wins over a later exception: say attempt N gets a 429 and is retried, then later attempts raise (e.g. a disconnect) until the 100-attempt cap. We now return or raise the stale 429 instead of
last_error. That matches the sync clients, so I'm fine keeping parity, but it might be worth a line in the description. - The description says the partial avoids changing how "a retried 429 with a malformed
{body is handled". Main was already lazy, so the partial keeps the current async behavior. Building eagerly wouldn't abort the retry. TheJSONDecodeErrorwould be caught byexcept Exceptionand the handler asked again, so each attempt would use up two retries. The new malformed-body tests do pin this. The sync clients still raise on the first malformed 429 without retrying; that predates this PR. - Optional: the post-loop return in webhook, SCIM and audit logs skips
_debug_log_response.
Summary
This pull request makes the async web, webhook, SCIM, and audit logs clients return the last response when their retries run out, as the sync clients already do.
Follow-up to #2085 (comment) (review thought on
raise last_error).last_errorwas stillNoneandraise last_errorraisedTypeError: exceptions must derive from BaseException.SlackApiErrorwith the 429, the other three return the 429 response, matching sync.returnin the spot refactor(web): remove unreachable resp checks from the async request loop #2085 removed as unreachable; with this change it is reachable.functools.partial), since their response classes parse the body. Building it on every retry would change how a retried 429 with a malformed{body is handled.Testing
test_ratelimited_returns_the_last_response_when_retries_run_outin each async client's retry tests, with a no-sleep handler that retries 429s 100 times. Each fails onmainwith theTypeErrorand passes here.Category
/docs(Documents)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.🤖 Generated with Claude Code