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 update_cell with invalid column key does not raise exception #3335

Closed
TomJGooding opened this issue Sep 17, 2023 · 2 comments · Fixed by #3336
Closed

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

TomJGooding opened this issue Sep 17, 2023 · 2 comments · Fixed by #3336

Comments

@TomJGooding
Copy link
Contributor

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()
@github-actions
Copy link

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

Copy link

github-actions bot commented Dec 5, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant