{"record":{"id":"2988b1528d0e3e83","repo":"Textualize/textual","slug":"no-column-exists-for-column-key-column-key-r","errorCode":null,"errorMessage":"No column exists for column_key={column_key!r}","messagePattern":"No column exists for column_key=(.+?)","errorType":"exception","errorClass":"ColumnDoesNotExist","httpStatus":null,"severity":"error","filePath":"src/textual/widgets/_data_table.py","lineNumber":1097,"sourceCode":"            raise ColumnDoesNotExist(f\"Column index {column_index!r} is not valid.\")\n\n        column_key = self._column_locations.get_key(column_index)\n        yield from self.get_column(column_key)\n\n    def get_column_index(self, column_key: ColumnKey | str) -> int:\n        \"\"\"Return the current index for the column identified by column_key.\n\n        Args:\n            column_key: The column key to find the current index of.\n\n        Returns:\n            The current index of the specified column key.\n\n        Raises:\n            ColumnDoesNotExist: If the column key does not exist.\n        \"\"\"\n        if column_key not in self._column_locations:\n            raise ColumnDoesNotExist(f\"No column exists for column_key={column_key!r}\")\n        return self._column_locations.get(column_key)\n\n    def _clear_caches(self) -> None:\n        self._row_render_cache.clear()\n        self._cell_render_cache.clear()\n        self._row_renderable_cache.clear()\n        self._line_cache.clear()\n        self._styles_cache.clear()\n        self._offset_cache.clear()\n        self._ordered_row_cache.clear()\n        self._get_styles_to_render_cell.cache_clear()\n\n    def get_row_height(self, row_key: RowKey) -> int:\n        \"\"\"Given a row key, return the height of that row in terminal cells.\n\n        Args:\n            row_key: The key of the row.\n","sourceCodeStart":1079,"sourceCodeEnd":1115,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widgets/_data_table.py#L1079-L1115","documentation":"Raised by DataTable.get_column_index when column_key is not in _column_locations. This key-to-index lookup fails for any column key that was never added or was removed/cleared. Useful for locating a column's current position after reordering.","triggerScenarios":"Calling get_column_index with an unknown or stale ColumnKey/string id; after remove_column or clear(); passing a RowKey by mistake.","commonSituations":"Mapping column keys to indices for sorting or styling after user-driven column changes; persisting column keys across app restarts where the table is rebuilt differently.","solutions":["Check if column_key in table.column_keys before calling.","Refresh stored column keys after any schema change (add/remove/clear).","Catch ColumnDoesNotExist and handle the missing-column case gracefully."],"exampleFix":"# before\nidx = table.get_column_index(col_key)\n\n# after\nidx = table.get_column_index(col_key) if col_key in table.column_keys else -1","handlingStrategy":"validation","validationCode":"idx = table.get_column_index(key) if key in table.column_keys else -1","typeGuard":null,"tryCatchPattern":"from textual.widgets._data_table import ColumnDoesNotExist\ntry:\n    idx = table.get_column_index(column_key)\nexcept ColumnDoesNotExist:\n    idx = -1","preventionTips":["Validate column keys before index lookups","Refresh key caches after add/remove/clear of columns"],"tags":["data-table","column-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"}