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

オープン 初心者向け
#6,769 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
cli

調査の方向性

クラッシュは textual/widgets/_data_table.py の _update_dimensions で起きています。そこでは、セグメントを描画しないセルに対して cell_renderable[0][0].style が読み取られています。まずそこのパディングループから始め、行スタイルのフォールバックがどうなっているかを確認してください。幅ゼロの最初の列と2行の2番目の列を使ってスニペットを実行します。行が2行で描画され、列Aが空で、IndexError が発生しなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
37.7k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Textualize/textual のほかの issue

Textualize/textual の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。