Textualize/textual · error · CellDoesNotExist

No cell exists at {coordinate!r}.

Error message

No cell exists at {coordinate!r}.

What it means

Raised by DataTable.coordinate_to_cell_key when the given Coordinate (row_index, column_index) fails is_valid_coordinate. This converts a screen-space cell position into its stable CellKey; invalid coordinates are any position outside the current row/column grid.

Source

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

                DataTable.CellHighlighted(
                    self, cell_value, coordinate=coordinate, cell_key=cell_key
                )
            )

    def coordinate_to_cell_key(self, coordinate: Coordinate) -> CellKey:
        """Return the key for the cell currently occupying this coordinate.

        Args:
            coordinate: The coordinate to exam the current cell key of.

        Returns:
            The key of the cell currently occupying this coordinate.

        Raises:
            CellDoesNotExist: If the coordinate is not valid.
        """
        if not self.is_valid_coordinate(coordinate):
            raise CellDoesNotExist(f"No cell exists at {coordinate!r}.")
        row_index, column_index = coordinate
        row_key = self._row_locations.get_key(row_index)
        column_key = self._column_locations.get_key(column_index)
        return CellKey(row_key, column_key)

    def _highlight_row(self, row_index: int) -> None:
        """Apply highlighting to the row at the given index, and post event."""
        self.refresh_row(row_index)
        is_valid_row = row_index < len(self._data)
        if is_valid_row:
            row_key = self._row_locations.get_key(row_index)
            self.post_message(DataTable.RowHighlighted(self, row_index, row_key))

    def _highlight_column(self, column_index: int) -> None:
        """Apply highlighting to the column at the given index, and post event."""
        self.refresh_column(column_index)
        if column_index < len(self.columns):
            column_key = self._column_locations.get_key(column_index)

View on GitHub (pinned to 06dbeef4bb)

Solutions

  1. Validate first: table.is_valid_coordinate(coordinate).
  2. Re-check row_count/column counts after async mutations before converting coordinates.
  3. Catch CellDoesNotExist around event handling that may race with table updates.
  4. Derive coordinates from table events rather than computing them by hand.

Example fix

# before
cell_key = table.coordinate_to_cell_key(coordinate)

# after
from textual.widgets._data_table import CellDoesNotExist
try:
    cell_key = table.coordinate_to_cell_key(coordinate)
except CellDoesNotExist:
    cell_key = None
Defensive patterns

Strategy: validation

Validate before calling

cell_key = table.coordinate_to_cell_key(coord) if table.is_valid_coordinate(coord) else None

Try / catch

from textual.widgets._data_table import CellDoesNotExist
try:
    cell_key = table.coordinate_to_cell_key(coord)
except CellDoesNotExist:
    cell_key = None

Prevention

When it happens

Trigger: Calling coordinate_to_cell_key with out-of-range row or column indices, e.g. from mouse event coordinate math, stale cursor positions, or coordinates computed before rows/columns were removed.

Common situations: Translating DataTable.CellSelected/CursorMoved event coordinates after the table shrank; handling mouse clicks while async updates remove rows; manually constructing Coordinate objects from widget-relative math.

Related errors


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