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

Tuple value for blocks argument does not work for Web API calls #1258

Closed
tommasobertoni opened this issue Aug 31, 2022 · 3 comments · Fixed by #1259
Closed

Tuple value for blocks argument does not work for Web API calls #1258

tommasobertoni opened this issue Aug 31, 2022 · 3 comments · Fixed by #1259
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x web-client
Milestone

Comments

@tommasobertoni
Copy link
Contributor

Both WebClient and AsyncWebClient accept a sequence of blocks (and attachments) but _parse_web_class_objects fails to serialize the objects into dictionaries since it only checks for lists via isinstance(blocks, list), therefore disagreeing with the clients' signature.

Impact on:

  • both sync and async clients
  • chat_postEphemeral, chat_postMessage, chat_scheduleMessage, chat_unfurl, chat_update
  • both Block and Attachment

Reproducible in:

The Slack SDK version

slack-sdk=3.18.1

Python runtime version

Python 3.10.3

OS info

ProductName:	macOS
ProductVersion:	12.5.1
BuildVersion:	21G83
Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000

Steps to reproduce:

client = WebClient(token="token")

# a tuple of blocks
blocks: Sequence[Block] = (
    SectionBlock(text="foo"),
    SectionBlock(text="bar"),
)

# works
client.chat_postMessage(channel="#channel", blocks=list(blocks))

# raises: Object of type SectionBlock is not JSON serializable
client.chat_postMessage(channel="#channel", blocks=blocks)

Expected result:

Since both clients accept a Sequence, one should be able to pass both a list or a tuple.

Actual result:

TypeError: Object of type SectionBlock is not JSON serializable since the blocks weren't serialized into dicts.

@seratch seratch changed the title Sequences of models are not serialized into dictionaries Tuple value for blocks argument does not work for Web API calls Aug 31, 2022
@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented web-client Version: 3x and removed untriaged labels Aug 31, 2022
@seratch seratch added this to the 3.18.2 milestone Aug 31, 2022
@seratch
Copy link
Member

seratch commented Aug 31, 2022

Hi @tommasobertoni, thanks for taking the time to report this issue!

You are right that blocks can be a tuple, but the current implementation does not work with the type. This issue can be resolved similarly to #1206 We will fix it in future versions. Until then, please consider going with list objects instead.

@tommasobertoni
Copy link
Contributor Author

Hi @seratch, I'm working on a PR for solving this issue, would that be ok?

@seratch
Copy link
Member

seratch commented Aug 31, 2022

@tommasobertoni As long as you are fine with 1) signing our Contributor License Agreement, and 2) writing some unit tests covering the patterns, your contributions are welcomed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x web-client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants