fix: handling markdown blocks in files_upload_v2 function - #1796
Closed
codomposer wants to merge 2 commits into
Closed
codomposer wants to merge 2 commits into
codomposer wants to merge 2 commits into
Conversation
Contributor
Author
|
@zimeg |
Member
|
Very high quality PR @codomposer ❤️ ⚡ Thanks for also updating the legacy client and adding tests for each scenario. 👌🏻 I'll let @zimeg give it a review when they're available. |
zimeg
reviewed
Nov 20, 2025
zimeg
left a comment
Member
There was a problem hiding this comment.
@codomposer Hmm I'm not confident the files.completeUploadExternal method is accepting the markdown block at this time and might require additional changes on the backend. FWIW other blocks appear to send as expected for me! 🤖
I did leave a comment on an alternative approach to this change as well, but please let me know if I'm overlooking something when testing these API calls.
Contributor
Author
|
hi @zimeg |
Contributor
Author
|
@zimeg |
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
Closes #1756
Bug Fix Summary: files_upload_v2 internal_error with markdown blocks
Problem
When using
files_upload_v2()with ablocksparameter containing markdown blocks, the Slack API returned aninternal_error:Root Cause
The
files_completeUploadExternal()method (called internally byfiles_upload_v2()) was not properly handling theblocksandattachmentsparameters:_parse_web_class_objects()call: This function converts Block objects to dictionaries, but it wasn't being calledblocksandattachmentsparameters need to be JSON-serialized strings when passed viaparams=kwargs, but they were being passed as Python listschat.postMessage()properly handle blocks by calling_parse_web_class_objects()and usingjson=kwargs(which auto-serializes) or manually serializing to JSON stringsSolution
Modified
files_completeUploadExternal()in bothslack_sdk/web/client.pyandslack_sdk/web/async_client.py:Changes in
slack_sdk/web/client.py(lines 4115-4126):What the fix does:
_parse_web_class_objects(kwargs): Converts any Block/Attachment objects to dictionariesFiles Modified
slack_sdk/web/client.py- Added blocks/attachments serialization logicslack_sdk/web/async_client.py- Auto-regenerated with the same fix usingscripts/codegen.pyslack_sdk/web/legacy_client.py- Auto-regenerated with the same fix usingscripts/codegen.pyUsage Examples
Before (would cause internal_error):
After (works correctly):
Impact
This fix ensures that
files_upload_v2()properly handles theblocksparameter in all its forms (list of dicts, Block objects, or JSON strings), making it consistent with other Slack SDK methods likechat.postMessage().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.Contribution by Gittensor, learn more at https://gittensor.io/