Textualize/textual · error · InvalidSelectValueError

Illegal select value {value!r}. Did you mean to use Select.c

Error message

Illegal select value {value!r}. Did you mean to use Select.clear()?

What it means

Raised by Select._validate_value when assigning a value not in the Select's legal values (the set of values from its options, plus the NULL/blank sentinel if allowed). Assigning None gets an extra hint because Textual uses a special NULL value rather than None for 'no selection'.

Source

Thrown at src/textual/widgets/_select.py:594

    def _validate_value(
        self, value: SelectType | NoSelection
    ) -> SelectType | NoSelection:
        """Ensure the new value is a valid option.

        If `allow_blank` is `True`, `None` is also a valid value and corresponds to no
            selection.

        Raises:
            InvalidSelectValueError: If the new value does not correspond to any known
                value.
        """
        if value not in self._legal_values:
            # It would make sense to use `None` to flag that the Select has no selection,
            # so we provide a helpful message to catch this mistake in case people didn't
            # realise we use a special value to flag "no selection".
            help_text = " Did you mean to use Select.clear()?" if value is None else ""
            raise InvalidSelectValueError(
                f"Illegal select value {value!r}." + help_text
            )

        return value

    def _watch_value(self, value: SelectType | NoSelection) -> None:
        """Update the current value when it changes."""
        self._value = value
        try:
            select_current = self.query_one(SelectCurrent)
        except NoMatches:
            pass
        else:
            if value == self.NULL:
                select_current.update(self.NULL)
            else:
                for index, (prompt, _value) in enumerate(self._options):
                    if _value == value:

View on GitHub (pinned to 06dbeef4bb)

Solutions

  1. To clear: call select.clear() (requires allow_blank=True) instead of assigning None.
  2. Ensure the value matches exactly (type and identity) one of the option values.
  3. Populate options first, then set value.

Example fix

# before
select.value = None
# after
select.clear()  # Select must have been created with allow_blank=True
Defensive patterns

Strategy: try-catch

Validate before calling

if value in {v for _, v in select._options} or value is select.NULL:
    select.value = value

Try / catch

from textual.widgets.select import InvalidSelectValueError
try:
    select.value = value
except InvalidSelectValueError:
    ...

Prevention

When it happens

Trigger: select.value = some_value not among the option values; select.value = None on a Select that doesn't allow blank (or ever — None is never legal, Select.NULL is the blank).

Common situations: Resetting state by assigning None, passing a raw id/enum from elsewhere that isn't among the options, or setting a value before options are populated.

Related errors


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