Pressing enter in a DataTable with rows but no columns raises `CellDoesNotExist`
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start in textual/widgets/_data_table.py at _post_selected_message and compare its existing no-rows early return with the no-columns case described here. Add coverage for pressing Enter with rows but no columns, including the row and column cursor types; done means no exception is raised and the empty-table behavior is preserved.
Written by the indexing model from the issue text.
Description
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.
- 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