Repository navigation
fix(web): raise SlackApiError for a malformed JSON body when retry handlers are set - #2073
Closed
tony1233200 wants to merge 1 commit into
Closed
tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
…ndlers are set
The retry loop in WebClient._perform_urllib_http_request parsed any 200
body starting with "{" with json.loads() and no guard, so a truncated
body surfaced as a raw JSONDecodeError. Leave "parsed_body" unset on a
decode error so _urllib_api_call() takes its existing fallback and
raises a SlackApiError, the same as without retry handlers.
Fixes slackapi#2070
|
Thanks for the contribution! Before we can merge this, we need @tony1233200 to sign the Salesforce Inc. Contributor License Agreement. |
mwbrooks
reviewed
Nov 19, 2026
mwbrooks
left a comment
Member
There was a problem hiding this comment.
Thanks @tony1233200 for the fix and the thorough tests! #2072 has the same change and was opened a few minutes earlier, so we'll take that one and close this as a duplicate. 🙇
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2070.
With retry handlers set (the default),
WebClientraises a rawjson.decoder.JSONDecodeErrorinstead of aSlackApiErrorwhen a 200 response body starts with{but is not valid JSON (for example a truncated body).Root cause: the retry loop in
WebClient._perform_urllib_http_requestcallsjson.loads(body_string)on any body starting with{, with no guard. The decode error escapes through theexcept Exceptionbranch before the graceful fallback in_urllib_api_callruns. Clients without retry handlers,AsyncWebClient, and bodies not starting with{already get aSlackApiError.Fix: catch
JSONDecodeErrorin that parse and leaveparsed_bodyunset, so_urllib_api_calltakes its existing fallback and raisesSlackApiError(Received a response in a non-JSON format: ...). This is the fix proposed in the issue.Testing
New
tests/slack_sdk/web/test_web_client_malformed_json_body.py(patches_perform_urllib_http_request_internalto return{"ok": tru):test_default_retry_handlersandtest_custom_retry_handlersfail withJSONDecodeError; the no-retry-handlers case and the well-formed-JSON case pass.Other checks:
ruff format --check slack/ slack_sdk/ tests/ integration_tests/(ruff 0.17.3 as pinned) andruff check slack/ slack_sdk/pass.pytest tests/slack_sdk/web tests/slack_sdk_async/web tests/slack_sdk/http_retry tests/slack_sdk_async/http_retry tests/slack_sdk/webhook: 140 passed, 4 skipped, 51 failed, identical to unmodifiedmain. All failures are in the async tests (aiohttp ServerDisconnectedErroragainst the local mock server) plustest_webhook.py::test_proxy_issue_714, because my sandbox forces an HTTP proxy through environment variables. None involve the sync retry path. All synctests/slack_sdk/webtests pass.Category
tests/integration_tests(Automated tests for this library)Requirements
./scripts/run_validation.sh(not run in full; I ran the format/lint checks and the relevant test subset listed above instead).