Skip to content

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

@tommasobertoni

Description

@tommasobertoni

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Version: 3xbugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documentedweb-client

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions