fix: handling markdown blocks in files_upload_v2 function #1796
+68
−5
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/