Textualize/textual · error · ColumnDoesNotExist

No column exists for column_key={column_key!r}

Error message

No column exists for column_key={column_key!r}

What it means

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.

Source

Thrown at src/textual/widgets/_data_table.py:1097

            raise ColumnDoesNotExist(f"Column index {column_index!r} is not valid.")

        column_key = self._column_locations.get_key(column_index)
        yield from self.get_column(column_key)

    def get_column_index(self, column_key: ColumnKey | str) -> int:
        """Return the current index for the column identified by column_key.

        Args:
            column_key: The column key to find the current index of.

        Returns:
            The current index of the specified column key.

        Raises:
            ColumnDoesNotExist: If the column key does not exist.
        """
        if column_key not in self._column_locations:
            raise ColumnDoesNotExist(f"No column exists for column_key={column_key!r}")
        return self._column_locations.get(column_key)

    def _clear_caches(self) -> None:
        self._row_render_cache.clear()
        self._cell_render_cache.clear()
        self._row_renderable_cache.clear()
        self._line_cache.clear()
        self._styles_cache.clear()
        self._offset_cache.clear()
        self._ordered_row_cache.clear()
        self._get_styles_to_render_cell.cache_clear()

    def get_row_height(self, row_key: RowKey) -> int:
        """Given a row key, return the height of that row in terminal cells.

        Args:
            row_key: The key of the row.

View on GitHub (pinned to 06dbeef4bb)

Solutions

  1. Check if column_key in table.column_keys before calling.
  2. Refresh stored column keys after any schema change (add/remove/clear).
  3. Catch ColumnDoesNotExist and handle the missing-column case gracefully.

Example fix

# before
idx = table.get_column_index(col_key)

# after
idx = table.get_column_index(col_key) if col_key in table.column_keys else -1
Defensive patterns

Strategy: validation

Validate before calling

idx = table.get_column_index(key) if key in table.column_keys else -1

Try / catch

from textual.widgets._data_table import ColumnDoesNotExist
try:
    idx = table.get_column_index(column_key)
except ColumnDoesNotExist:
    idx = -1

Prevention

When it happens

Trigger: Calling get_column_index with an unknown or stale ColumnKey/string id; after remove_column or clear(); passing a RowKey by mistake.

Common situations: 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.

Related errors


AI-assisted analysis of Textualize/textual@06dbeef4bb (2026-08-27). Data as JSON: /api/errors/2988b1528d0e3e83. Report an issue: GitHub.