{"record":{"id":"1b92c64dad84c484","repo":"Textualize/textual","slug":"no-row-exists-for-row-key-row-key-r","errorCode":null,"errorMessage":"No row exists for row_key={row_key!r}","messagePattern":"No row exists for row_key=(.+?)","errorType":"exception","errorClass":"RowDoesNotExist","httpStatus":null,"severity":"error","filePath":"src/textual/widgets/_data_table.py","lineNumber":1043,"sourceCode":"        if not self.is_valid_row_index(row_index):\n            raise RowDoesNotExist(f\"Row index {row_index!r} is not valid.\")\n        row_key = self._row_locations.get_key(row_index)\n        return self.get_row(row_key)\n\n    def get_row_index(self, row_key: RowKey | str) -> int:\n        \"\"\"Return the current index for the row identified by row_key.\n\n        Args:\n            row_key: The row key to find the current index of.\n\n        Returns:\n            The current index of the specified row key.\n\n        Raises:\n            RowDoesNotExist: If the row key does not exist.\n        \"\"\"\n        if row_key not in self._row_locations:\n            raise RowDoesNotExist(f\"No row exists for row_key={row_key!r}\")\n        return self._row_locations.get(row_key)\n\n    def get_column(self, column_key: ColumnKey | str) -> Iterable[CellType]:\n        \"\"\"Get the values from the column identified by the given column key.\n\n        Args:\n            column_key: The key of the column.\n\n        Returns:\n            A generator which yields the cells in the column.\n\n        Raises:\n            ColumnDoesNotExist: If there is no column corresponding to the key.\n        \"\"\"\n        if column_key not in self._column_locations:\n            raise ColumnDoesNotExist(f\"Column key {column_key!r} is not valid.\")\n\n        data = self._data","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widgets/_data_table.py#L1025-L1061","documentation":"Raised by DataTable.get_row_index when row_key is not in _row_locations. This is the key-to-index lookup used to find where a row currently sits; an unknown key means the row was never added or has since been removed/cleared.","triggerScenarios":"Calling get_row_index with a string/RowKey that does not match any row added via add_row; using keys after clear(); mixing keys between DataTable instances.","commonSituations":"Translating row keys to indices after a table rebuild; handling DataTableRowSelected/DataTableRowCursorMoved events for rows already deleted; storing event row keys and replaying them later.","solutions":["Guard the lookup: if key in table._row_locations or catch RowDoesNotExist around get_row_index.","Handle rows being removed between event and handler by refreshing state before lookup.","Use the key returned from add_row rather than reconstructing keys manually.","After clear(), discard all previously saved keys."],"exampleFix":"# before\nindex = table.get_row_index(row_key)\n\n# after\nfrom textual.widgets._data_table import RowDoesNotExist\ntry:\n    index = table.get_row_index(row_key)\nexcept RowDoesNotExist:\n    index = -1","handlingStrategy":"try-catch","validationCode":"index = table.get_row_index(key) if key in table.row_keys else -1","typeGuard":null,"tryCatchPattern":"from textual.widgets._data_table import RowDoesNotExist\ntry:\n    idx = table.get_row_index(row_key)\nexcept RowDoesNotExist:\n    idx = -1","preventionTips":["Treat row keys as ephemeral after mutations","Validate event-supplied keys before use","Discard saved keys on clear()"],"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"}