Pressing enter in a DataTable with rows but no columns raises `CellDoesNotExist`

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

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

評価

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

調査の方向性

textual/widgets/_data_table.py の _post_selected_message から始めて、既存の行がない場合の早期リターンを、ここで説明している列がない場合と比較してください。行はあるが列がない状態で Enter を押す場合のテストを追加してください。カーソルの種類 row と column も含めてください。例外が発生せず、空のテーブルでの動作が維持されていれば完了です。

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

説明

Hi! I hit this while writing generated tests against Textual's widgets. If a DataTable has rows but no columns yet (for example, rows added before the columns), pressing enter crashes the app.

from textual.app import App, ComposeResult
from textual.widgets import DataTable

class NoColumnsApp(App):
    def compose(self) -> ComposeResult:
        yield DataTable()

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_row()
        table.focus()

if __name__ == "__main__":
    NoColumnsApp().run()  # then press enter

Expected: nothing happens, as with an empty table.

Actual (on Textual 8.2.7, and main at 5e5b7ef):

  File "textual/widgets/_data_table.py", line 2839, in action_select_cursor
    self._post_selected_message()
  File "textual/widgets/_data_table.py", line 2847, in _post_selected_message
    cell_key = self.coordinate_to_cell_key(cursor_coordinate)
  File "textual/widgets/_data_table.py", line 1291, in coordinate_to_cell_key
    raise CellDoesNotExist(f"No cell exists at {coordinate!r}.")
textual.widgets._data_table.CellDoesNotExist: No cell exists at Coordinate(row=0, column=0).

The same happens with cursor_type set to "row" or "column". _post_selected_message already returns early when there are no rows (the fix for #1970); it doesn't check for columns.

I'd suggest returning early when there are no columns as well. For the row cursor you could argue a RowSelected should still be posted, but that would need a cell key without a column, so returning early seemed the smaller change. 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 を短くまとめたダイジェスト。