Textualize/textual · error · ColumnDoesNotExist

Column key {column_key!r} is not valid.

Error message

Column key {column_key!r} is not valid.

What it means

Raised by DataTable.get_column when column_key is not in _column_locations. Columns are identified by ColumnKey (or its string id) assigned at add_column time; this error means no such column exists. get_column_at and internal width updates also funnel through here.

Source

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

        """
        if row_key not in self._row_locations:
            raise RowDoesNotExist(f"No row exists for row_key={row_key!r}")
        return self._row_locations.get(row_key)

    def get_column(self, column_key: ColumnKey | str) -> Iterable[CellType]:
        """Get the values from the column identified by the given column key.

        Args:
            column_key: The key of the column.

        Returns:
            A generator which yields the cells in the column.

        Raises:
            ColumnDoesNotExist: If there is no column corresponding to the key.
        """
        if column_key not in self._column_locations:
            raise ColumnDoesNotExist(f"Column key {column_key!r} is not valid.")

        data = self._data
        for row_metadata in self.ordered_rows:
            row_key = row_metadata.key
            yield data[row_key][column_key]

    def get_column_at(self, column_index: int) -> Iterable[CellType]:
        """Get the values from the column at a given index.

        Args:
            column_index: The index of the column.

        Returns:
            A generator which yields the cells in the column.

        Raises:
            ColumnDoesNotExist: If there is no column with the given index.
        """

View on GitHub (pinned to 06dbeef4bb)

Solutions

  1. Check membership first: if column_key in table.column_keys.
  2. Capture and reuse the ColumnKey instances returned from add_column.
  3. Invalidate cached keys whenever remove_column or clear is called.
  4. Catch ColumnDoesNotExist as a safety net.

Example fix

# before
values = list(table.get_column(col_key))

# after
from textual.widgets._data_table import ColumnDoesNotExist
try:
    values = list(table.get_column(col_key))
except ColumnDoesNotExist:
    values = []
Defensive patterns

Strategy: validation

Validate before calling

values = list(table.get_column(col_key)) if col_key in table.column_keys else []

Try / catch

from textual.widgets._data_table import ColumnDoesNotExist
try:
    values = list(table.get_column(col_key))
except ColumnDoesNotExist:
    values = []

Prevention

When it happens

Trigger: Calling get_column with a key that was never returned by add_column; a key whose column was removed via remove_column; a key from before clear() was called.

Common situations: Caching column keys across table rebuilds; passing a row key where a column key is expected; referencing dynamically generated columns by guessed string ids.

Related errors


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