Repository navigation
Conversation
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 Report❌ Patch coverage is
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. |
…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>
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
left a comment
There was a problem hiding this comment.
📝 A few notes for the amazing readers and kind reviewers.
| CarouselBlock(elements=[]).validate_json() | ||
|
|
||
|
|
||
| class DataTableBlockTests(unittest.TestCase): |
There was a problem hiding this comment.
📇 note: These tests follow CarouselBlock and holds off on wider orderings for now.
| # ---------------------------------------------- | ||
| # RawNumberObject | ||
| # ---------------------------------------------- |
There was a problem hiding this comment.
🎲 note: This and the RawTextObject following might later be moved to tests for composition objects perhaps?
# Conflicts: # slack_sdk/models/blocks/blocks.py # tests/slack_sdk/models/test_blocks.py
zimeg
left a comment
There was a problem hiding this comment.
🧮 Some question of implementation we'll ask more ongoing with tests
| # 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) |
There was a problem hiding this comment.
🪬 question: How strict needed is this logic? The late import troubles me a little...
There was a problem hiding this comment.
🪬 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.
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
left a comment
There was a problem hiding this comment.
🧪 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 🙏
| def _validate_caption(self): | ||
| return self.caption is not None |
There was a problem hiding this comment.
🧠 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?
| def _validate_caption(self): | |
| return self.caption is not None | |
| def _validate_caption(self): | |
| return bool(self.caption) |
| def _validate_rows(self): | ||
| return self.rows is not None and len(self.rows) > 0 |
There was a problem hiding this comment.
🧠 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
| [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()], |
There was a problem hiding this comment.
🧪 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.
| [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__) |
There was a problem hiding this comment.
🪓 suggestion (non-blocking): I don't think we need this logger, nothing in RawNumberObject uses it.
| logger = logging.getLogger(__name__) |
| def __init__( | ||
| self, | ||
| *, | ||
| rows: Sequence[Sequence[Union[RawTextObject, RawNumberObject, RichTextBlock, Dict[str, Any]]]], |
There was a problem hiding this comment.
🔭 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 |
There was a problem hiding this comment.
🪓 suggestion (non-blocking): Could we let the call speak for itself, or assert on the output instead of the comment?
| obj.to_dict() # Should not raise | |
| self.assertEqual(obj.to_dict()["text"], "1") |
| 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 |
There was a problem hiding this comment.
🪓 suggestion (non-blocking): Same here, I think the call below reads fine without it.
| # A valid page_size should pass |
| block_id: Optional[str] = None, | ||
| **others: dict, | ||
| ): | ||
| """Displays rich tables that support pagination, sorting, filtering, and interactivity. |
There was a problem hiding this comment.
📚 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""" |
There was a problem hiding this comment.
🪓 nitpick (non-blocking): The test docstrings mostly repeat the method names; I think the names already say it, so they could go.
| ], | ||
| } | ||
| self.assertDictEqual(input, DataTableBlock(**input).to_dict()) | ||
| self.assertDictEqual(input, Block.parse(input).to_dict()) |
There was a problem hiding this comment.
💯 praise: Round-tripping each fixture through both the constructor and Block.parse is a nice touch, it pins the new parse branch too.
Summary
Adds the net-new
data_tableBlock Kit block to the SDK models. The block displays structured, paginated data in a table with a required caption.DataTableBlockwithrows(required),caption(required),page_size,row_header_column_index, andblock_iddata_tabletype inBlock.parseDataTableBlockfromslack_sdk.models.blocksrows/captionandpage_sizerange (1-100)ActionCellObjectforaction_cellcells (a required buttonelementand an optionalraw_text/raw_numberfallback), parsed inDataTableBlockrows only since action cells aren't allowed intable, and exported fromslack_sdk.models.blocksmainto resolve conflicts withAuthProviderBlockand the already-mergedRawNumberObject(feat(models): allow raw_number cells in TableBlock rows #1964), keeping main's versionsTableBlocktests (basic doc example, all fields, rich_text cells, empty-rows validation, required caption, page_size range), plusaction_cellround-trips with and withoutfallbackand element/fallback validationCell types
raw_text/raw_number/rich_textare passed through as given, matching the existingTableBlockconvention in this repo.action_celldicts are parsed intoActionCellObjectso 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 issuespytest tests/-> passing (one unrelated rate-limit retry test flaked once and passed on rerun)One block per PR;
data_visualizationis intentionally not included here.