DataTable auto-height row with a zero-width cell raises `IndexError`

Open Beginner friendly
#6,769 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cli

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Textualize/textual

All issues in Textualize/textual

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.