Skip to content

feat(models): add data_table Block Kit block - #1900

Open
zimeg wants to merge 24 commits into
mainfrom
chore/block-kit-data-table-wt
Open

zimeg wants to merge 24 commits into
mainfrom
chore/block-kit-data-table-wt

Conversation

@zimeg

@zimeg zimeg commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the net-new data_table Block Kit block to the SDK models. The block displays structured, paginated data in a table with a required caption.

  • DataTableBlock with rows (required), caption (required), page_size, row_header_column_index, and block_id
  • Registered the data_table type in Block.parse
  • Exported DataTableBlock from slack_sdk.models.blocks
  • Validators for required rows/caption and page_size range (1-100)
  • ActionCellObject for action_cell cells (a required button element and an optional raw_text/raw_number fallback), parsed in DataTableBlock rows only since action cells aren't allowed in table, and exported from slack_sdk.models.blocks
  • Merged main to resolve conflicts with AuthProviderBlock and the already-merged RawNumberObject (feat(models): allow raw_number cells in TableBlock rows #1964), keeping main's versions
  • Tests mirroring the existing TableBlock tests (basic doc example, all fields, rich_text cells, empty-rows validation, required caption, page_size range), plus action_cell round-trips with and without fallback and element/fallback validation

Cell types raw_text / raw_number / rich_text are passed through as given, matching the existing TableBlock convention in this repo. action_cell dicts are parsed into ActionCellObject so the button element is validated.

Reference

https://docs.slack.dev/reference/block-kit/blocks/data-table-block

Validation

Run in a fresh venv (./scripts/install.sh, Python 3.14):

  • ./scripts/run_tests.sh tests/slack_sdk/models/test_blocks.py -> 133 passed
  • ./scripts/lint.sh -> clean
  • ./scripts/run_mypy.sh -> no issues
  • Full pytest tests/ -> passing (one unrelated rate-limit retry test flaked once and passed on rerun)

One block per PR; data_visualization is intentionally not included here.

Add the net-new `data_table` block to the Block Kit models. The block
displays structured, paginated data with a required caption.

- DataTableBlock with rows (required), caption (required), page_size,
  row_header_column_index, and block_id
- register the type in Block.parse and export it from
  slack_sdk.models.blocks
- validators for required rows/caption and page_size range (1-100)
- tests mirroring the existing TableBlock tests

Ref: https://docs.slack.dev/reference/block-kit/blocks/data-table-block

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@codecov

codecov Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.52%. Comparing base (6a772c6) to head (b970845).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
slack_sdk/models/blocks/basic_components.py 85.71% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1900   +/-   ##
=======================================
  Coverage   84.51%   84.52%           
=======================================
  Files         118      118           
  Lines       14037    14087   +50     
=======================================
+ Hits        11864    11907   +43     
- Misses       2173     2180    +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

zimeg and others added 4 commits September 8, 2026 17:04
…ects

Mirrors node-slack-sdk#2638: data_table rows accept raw_text, raw_number,
and rich_text cells. Adds RawNumberObject (value + display text, min-length-1)
and widens DataTableBlock.rows to Union[RawTextObject, RawNumberObject,
RichTextBlock, Dict]. Field wording tracks the docs/node model verbatim.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
raw_number has no dedicated composition-object reference page (it is only
documented inline on the data-table-block page). Match node-slack-sdk#2638's
RawNumberElement, which deliberately carries no @see link for the same reason.
The DataTableBlock docstring keeps the URL — that page is the block's own home.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Match the recently-added sibling blocks (AlertBlock, CardBlock, ContainerBlock,
CarouselBlock), which all use the one-line block_id description. DataTableBlock
had inherited the legacy verbose 5-line variant.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg added enhancement M-T: A feature request for new functionality semver:minor models labels Sep 9, 2026
@zimeg zimeg self-assigned this Sep 9, 2026
zimeg and others added 3 commits September 8, 2026 17:32
The docs data-table-block Fields table (and node-slack-sdk#2638) describe rows
as exactly 'An array consisting of table rows.' — drop the extra cell-type
sentence that was appended, per the verbatim-docs-field convention.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Matches both alphabetical order (Number < Text) and node-slack-sdk#2638's
composition-objects order (RawNumberElement before RawTextElement). No behavior
change — RawNumberObject extends JsonObject, so it has no dependency on the
sibling class.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Match the class order in the source files:
- RawNumberObjectTests before RawTextObjectTests (Number before Text, as in
  basic_components.py and node-slack-sdk#2638).
- DataTableBlockTests moved to the end, after CarouselBlockTests, mirroring
  DataTableBlock's position at the end of blocks.py.
Pre-existing test ordering left untouched (out of scope for this PR).

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 A few notes for the amazing readers and kind reviewers.

CarouselBlock(elements=[]).validate_json()


class DataTableBlockTests(unittest.TestCase):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📇 note: These tests follow CarouselBlock and holds off on wider orderings for now.

Comment on lines +1363 to +1365
# ----------------------------------------------
# RawNumberObject
# ----------------------------------------------

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎲 note: This and the RawTextObject following might later be moved to tests for composition objects perhaps?

@zimeg
zimeg marked this pull request as ready for review September 9, 2026 02:58
@zimeg
zimeg requested a review from a team as a code owner September 9, 2026 02:58
@zimeg zimeg added this to the 3.next milestone Sep 9, 2026
@zimeg zimeg modified the milestones: 3.45.0, 3.next Oct 1, 2026
@zimeg zimeg modified the milestones: 3.46.0, 3.47.0 Oct 30, 2026

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧮 Some question of implementation we'll ask more ongoing with tests

Comment on lines +190 to +202
# Imported here since block_elements imports this module
from .block_elements import BlockElement

show_unknown_key_warning(self, others)
self.element = BlockElement.parse(element)
self.fallback = fallback
if isinstance(fallback, dict):
d = copy.copy(fallback)
t = d.pop("type", None)
if t == RawNumberObject.type:
self.fallback = RawNumberObject(**d)
elif t == RawTextObject.type:
self.fallback = RawTextObject(**d)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪬 question: How strict needed is this logic? The late import troubles me a little...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪬 Loosened in 41ca228. element and fallback are now stored as given, the same way TableBlock handles its raw_text/raw_number cells, which never get parsed into typed objects. Removing the BlockElement.parse call removes the late import, and the fallback type dispatch and the button/fallback type validators are gone too. The API still enforces those rules from the docs. I kept the element required check. The other option was moving ActionCellObject into block_elements.py (like ConversationFilter), but that would split it from the other cells.

zimeg and others added 2 commits November 9, 2026 14:26
drops the late block_elements import and the fallback type dispatch so
action cells pass through like the other table cells. tests trim to one
parse and one build each for ActionCellObject and DataTableBlock.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Thanks @zimeg! The round-trip tests against the docs examples and the page_size bounds make this block easy to trust.
One blocking comment around an empty caption getting dropped from the payload, the rest are take it or leave it 🙏

Comment on lines +1209 to +1210
def _validate_caption(self):
return self.caption is not None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 issue (blocking): I think an empty caption="" slips through here. It passes this check, then to_dict() drops empty values, so the payload goes out with no caption at all even though the docs mark it required. Could we check for a non-empty string instead?

Suggested change
def _validate_caption(self):
return self.caption is not None
def _validate_caption(self):
return bool(self.caption)

Comment on lines +1205 to +1206
def _validate_rows(self):
return self.rows is not None and len(self.rows) > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 suggestion (non-blocking): The docs list a few more shape limits that pass today: at least 2 rows (header plus one) and at most 201, 1 to 20 columns, every row the same length, and a row_header_column_index inside the columns. A header-only table, ragged rows, 21 columns and 202 rows all serialize fine right now. What do you think about a validator or two for these, since the API will reject them anyway? Happy for this to be a follow-up if you want parity with TableBlock first. https://docs.slack.dev/reference/block-kit/blocks/data-table-block#usage

Comment thread tests/slack_sdk/models/test_blocks.py Outdated
Comment on lines +2023 to +2025
[RawTextObject(text="Region").to_dict(), RawTextObject(text="Sales").to_dict()],
[RawTextObject(text="West").to_dict(), RawNumberObject(value=120, text="120").to_dict()],
[RawTextObject(text="East").to_dict(), RawNumberObject(value=95, text="95").to_dict()],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 suggestion (non-blocking): Since rows now types RawTextObject and RawNumberObject, could we pass the objects straight in here? Calling .to_dict() first means the typed path never gets exercised, and it does serialize nested objects correctly when passed directly.

Suggested change
[RawTextObject(text="Region").to_dict(), RawTextObject(text="Sales").to_dict()],
[RawTextObject(text="West").to_dict(), RawNumberObject(value=120, text="120").to_dict()],
[RawTextObject(text="East").to_dict(), RawNumberObject(value=95, text="95").to_dict()],
[RawTextObject(text="Region"), RawTextObject(text="Sales")],
[RawTextObject(text="West"), RawNumberObject(value=120, text="120")],
[RawTextObject(text="East"), RawNumberObject(value=95, text="95")],


type = "raw_number"
attributes = {"value", "text", "type"}
logger = logging.getLogger(__name__)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 suggestion (non-blocking): I don't think we need this logger, nothing in RawNumberObject uses it.

Suggested change
logger = logging.getLogger(__name__)

Comment thread slack_sdk/models/blocks/blocks.py Outdated
def __init__(
self,
*,
rows: Sequence[Sequence[Union[RawTextObject, RawNumberObject, RichTextBlock, Dict[str, Any]]]],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔭 question (non-blocking): The docs also list action_cell (a button with an optional raw_text/raw_number fallback). It works today as a dict, so nothing blocks, but should we track an ActionCellObject helper as a follow-up so the typed cells cover all four?

def test_text_length_validation_at_min(self):
"""Test that text with 1 character passes validation"""
obj = RawNumberObject(value=1, text="1")
obj.to_dict() # Should not raise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 suggestion (non-blocking): Could we let the call speak for itself, or assert on the output instead of the comment?

Suggested change
obj.to_dict() # Should not raise
self.assertEqual(obj.to_dict()["text"], "1")

Comment thread tests/slack_sdk/models/test_blocks.py Outdated
DataTableBlock(caption="too small", rows=rows, page_size=0).to_dict()
with self.assertRaises(SlackObjectFormationError):
DataTableBlock(caption="too big", rows=rows, page_size=101).to_dict()
# A valid page_size should pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 suggestion (non-blocking): Same here, I think the call below reads fine without it.

Suggested change
# A valid page_size should pass

block_id: Optional[str] = None,
**others: dict,
):
"""Displays rich tables that support pagination, sorting, filtering, and interactivity.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 suggestion (non-blocking): These field descriptions (here and on RawNumberObject) copy the docs.slack.dev text, which I think might drift as the block evolves. What do you think about keeping just the docs link and letting the typed signature carry the rest?


class RawNumberObjectTests(unittest.TestCase):
def test_basic_creation(self):
"""Test basic RawNumberObject creation"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 nitpick (non-blocking): The test docstrings mostly repeat the method names; I think the names already say it, so they could go.

Comment thread tests/slack_sdk/models/test_blocks.py Outdated
],
}
self.assertDictEqual(input, DataTableBlock(**input).to_dict())
self.assertDictEqual(input, Block.parse(input).to_dict())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 praise: Round-tripping each fixture through both the constructor and Block.parse is a nice touch, it pins the new parse branch too.

@zimeg zimeg mentioned this pull request Nov 13, 2026
5 of 15 tasks
@zimeg zimeg modified the milestones: 3.47.0, 3.47.1 Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality models semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants