Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable - fix crash when selection made in empty table #1973

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fixed bug that prevented pilot from pressing some keys https://github.com/Textualize/textual/issues/1815
- DataTable race condition that caused crash https://github.com/Textualize/textual/pull/1962
- DataTable crash when enter pressed when table is empty https://github.com/Textualize/textual/pull/1973

## [0.13.0] - 2023-03-02

Expand Down
2 changes: 2 additions & 0 deletions src/textual/widgets/_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,8 @@ def _post_selected_message(self):
"""Post the appropriate message for a selection based on the `cursor_type`."""
cursor_coordinate = self.cursor_coordinate
cursor_type = self.cursor_type
if len(self._data) == 0:
return
cell_key = self.coordinate_to_cell_key(cursor_coordinate)
if cursor_type == "cell":
self.post_message(
Expand Down
9 changes: 7 additions & 2 deletions tests/test_data_table.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from __future__ import annotations

import pytest
from rich.style import Style
from rich.text import Text

from textual._wait import wait_for_idle
from textual.actions import SkipAction
from textual.app import App
from textual.coordinate import Coordinate
from textual.events import Click, MouseMove
from textual.geometry import Offset
from textual.message import Message
from textual.widgets import DataTable
Expand Down Expand Up @@ -166,6 +164,13 @@ async def test_datatable_message_emission():
assert app.message_names == expected_messages


async def test_empty_table_interactions():
app = DataTableApp()
async with app.run_test() as pilot:
await pilot.press("enter", "up", "down", "left", "right")
assert app.message_names == []


async def test_add_rows():
app = DataTableApp()
async with app.run_test():
Expand Down