{"record":{"id":"5b51b65c3b07047e","repo":"Textualize/textual","slug":"row-key-row-key-r-is-not-valid","errorCode":null,"errorMessage":"Row key {row_key!r} is not valid.","messagePattern":"Row key (.+?) is not valid\\.","errorType":"exception","errorClass":"RowDoesNotExist","httpStatus":null,"severity":"error","filePath":"src/textual/widgets/_data_table.py","lineNumber":1004,"sourceCode":"            )\n        row_index = self._row_locations.get(row_key)\n        column_index = self._column_locations.get(column_key)\n        return Coordinate(row_index, column_index)\n\n    def get_row(self, row_key: RowKey | str) -> list[CellType]:\n        \"\"\"Get the values from the row identified by the given row key.\n\n        Args:\n            row_key: The key of the row.\n\n        Returns:\n            A list of the values contained within the row.\n\n        Raises:\n            RowDoesNotExist: When there is no row corresponding to the key.\n        \"\"\"\n        if row_key not in self._row_locations:\n            raise RowDoesNotExist(f\"Row key {row_key!r} is not valid.\")\n        cell_mapping: dict[ColumnKey, CellType] = self._data.get(row_key, {})\n        ordered_row: list[CellType] = [\n            cell_mapping[column.key] for column in self.ordered_columns\n        ]\n        return ordered_row\n\n    def get_row_at(self, row_index: int) -> list[CellType]:\n        \"\"\"Get the values from the cells in a row at a given index. This will\n        return the values from a row based on the rows _current position_ in\n        the table.\n\n        Args:\n            row_index: The index of the row.\n\n        Returns:\n            A list of the values contained in the row.\n\n        Raises:","sourceCodeStart":986,"sourceCodeEnd":1022,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widgets/_data_table.py#L986-L1022","documentation":"Raised by DataTable.get_row when the supplied row_key is not present in the table's internal _row_locations mapping. Textual uses stable RowKey objects (or their string ids) to track rows independently of their visual position, so this error means no row with that key has ever been added (or it was removed/cleared). It is the canonical 'unknown row key' error for key-based row access.","triggerScenarios":"Calling table.get_row(key) with a key that was never returned by add_row/add_columns+add_row, a key from a table that had clear() called on it, a key from a different DataTable instance, or a key of a row removed via remove_row.","commonSituations":"Reusing stale row keys captured before a table refresh/clear; passing a ColumnKey where a RowKey is expected; rebuilding table data asynchronously while a callback still holds old keys; typos in string keys supplied to add_row(key=...).","solutions":["Verify the key exists first: if row_key in table.row_keys or catch RowDoesNotExist.","Re-fetch keys from the table after clear()/re-population instead of caching them across rebuilds.","Ensure you are passing the RowKey returned by add_row(), not an index or a ColumnKey.","If rows were removed, guard with table.get_row_index(row_key) inside try/except RowDoesNotExist before calling get_row."],"exampleFix":"// before\nrow = table.get_row(stale_key)\n\n// after\nfrom textual.widgets._data_table import RowDoesNotExist\ntry:\n    row = table.get_row(stale_key)\nexcept RowDoesNotExist:\n    row = None","handlingStrategy":"try-catch","validationCode":"key_exists = row_key in table.row_keys\nrow = table.get_row(row_key) if key_exists else None","typeGuard":"from textual.widgets._data_table import RowKey\n\ndef is_live_row_key(table: DataTable, key: object) -> bool:\n    return isinstance(key, (RowKey, str)) and key in table._row_locations","tryCatchPattern":"from textual.widgets._data_table import RowDoesNotExist\ntry:\n    row = table.get_row(row_key)\nexcept RowDoesNotExist:\n    row = None  # treat as missing","preventionTips":["Never cache row keys across clear() calls","Use keys returned by add_row()","Guard lookups with row_keys membership when rows can be removed"],"tags":["data-table","row-key","textual","lookup-failed"],"backgroundTag":"dict-key-not-found","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}