DataTable auto-height row with a zero-width cell raises `IndexError`
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The crash is in _update_dimensions in textual/widgets/_data_table.py, where cell_renderable[0][0].style is read for a cell that renders no segments. Start with the padding loop there and check what the row style fallback looks like. Run the snippet with a zero-width first column and a two-line second column; done means the row renders two lines with column A empty and no IndexError.
Written by the indexing model from the issue text.
Description
Hi! I hit this while writing generated tests against Textual's widgets. In a row added with height=None, if one cell renders zero cells wide and another cell is taller, the table crashes when it measures the row.
from textual.app import App, ComposeResult
from textual.widgets import DataTable
class AutoHeightApp(App):
def compose(self) -> ComposeResult:
yield DataTable(cell_padding=0)
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_column("A", width=0)
table.add_column("B")
table.add_row("x", "two\nlines", height=None)
if __name__ == "__main__":
AutoHeightApp().run()
Expected: a two-line row, with column A empty.
Actual (on Textual 8.2.7, and main at 5e5b7ef):
File "textual/widgets/_data_table.py", line 1891, in _on_idle
self._update_dimensions(new_rows)
File "textual/widgets/_data_table.py", line 1496, in _update_dimensions
first_line_space_style = cell_renderable[0][0].style
IndexError: list index out of range
When a cell is shorter than the row, _update_dimensions pads it with blank lines styled like its first segment. A zero-width cell renders no segments, so cell_renderable[0][0] doesn't exist.
I'd suggest falling back to the row style when the cell rendered nothing. I'm happy to send a PR.
- Dominant language
- Python
- Stars
- 37.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/textual
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6790 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Textualize/textual#6789 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6787 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6782 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Textualize/textual#6778 · 1 comment ·
All issues in Textualize/textual
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day