Skip to content

DataTable update_cell with invalid column key does not raise exception #3335

@TomJGooding

Description

@TomJGooding

Currently the DataTable will only raise a CellDoesNotExist error if the row key does not exist, but not if the column key does not exist.

Here's a simple example which also logs the table _data:

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


class TableApp(App):
    CSS = """
    DataTable {
        height: 1fr;
        border: double $primary;
    }

    RichLog {
        height: 1fr;
        border: double $primary;
    }
    """

    def compose(self) -> ComposeResult:
        yield DataTable()
        yield RichLog()

    def on_mount(self) -> None:
        table = app.query_one(DataTable)
        table.border_title = "Table View"
        table.add_column("Column1", key="C1")
        table.add_row("TargetValue", key="R1")

        log = self.query_one(RichLog)
        log.border_title = "Table Data"
        log.write("DataTable._data = ")
        log.write(table._data)

    def key_u(self) -> None:
        table = self.query_one(DataTable)
        table.update_cell("R1", "INVALID_COLUMN", "New Value")

        log = self.query_one(RichLog)
        log.write("\nDataTable._data = ")
        log.write(table._data)


app = TableApp()
if __name__ == "__main__":
    app.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions