Textualize/textual · error · EmptySelectError

Select options cannot be empty if selection can't be blank.

Error message

Select options cannot be empty if selection can't be blank.

What it means

Raised by Select's internal _setup_variables_for_options (used by __init__ and set_options) when the resulting options list is empty and allow_blank is False. With no options and no blank entry, the Select would have no legal value at all, so construction fails with EmptySelectError.

Source

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

        if isinstance(value, NoSelection):
            return None
        return value

    def _setup_variables_for_options(
        self,
        options: Iterable[tuple[RenderableType, SelectType]],
    ) -> None:
        """Setup function for the auxiliary variables related to options.

        This method sets up `self._options` and `self._legal_values`.
        """
        self._options: list[tuple[RenderableType, SelectType | NoSelection]] = []
        if self._allow_blank:
            self._options.append(("", self.NULL))
        self._options.extend(options)

        if not self._options:
            raise EmptySelectError(
                "Select options cannot be empty if selection can't be blank."
            )

        self._legal_values: set[SelectType | NoSelection] = {
            value for _, value in self._options
        }

    def _setup_options_renderables(self) -> None:
        """Sets up the `Option` renderables associated with the `Select` options."""
        options: list[Option] = [
            (
                Option(Text(self.prompt, style="dim"))
                if value == self.NULL
                else Option(prompt)
            )
            for prompt, value in self._options
        ]

View on GitHub (pinned to 06dbeef4bb)

Solutions

  1. Set allow_blank=True when the option source may be empty.
  2. Guard before construction: skip creating the Select or show a placeholder message when options is empty.
  3. Feed a non-empty default option list.

Example fix

# before
Select(options(), allow_blank=False)  # options() may return []
# after
if not options():
    mount(Label('No options available'))
else:
    mount(Select(options(), allow_blank=False))
Defensive patterns

Strategy: validation

Validate before calling

opts = list(options)
if not opts:
    opts = [('', None)]  # or skip mounting
select = Select(opts, allow_blank=bool(opts) or allow_blank)

Try / catch

from textual.widgets.select import EmptySelectError
try:
    Select([], allow_blank=False)
except EmptySelectError:
    ...

Prevention

When it happens

Trigger: Select([], allow_blank=False), Select(options=[], prompt='Pick') with default allow_blank=False, or set_options([]) on a Select created with allow_blank=False.

Common situations: Building a Select from a dynamic query that returns zero results (empty DB/api response), or filtering options down to nothing before rendering.

Related errors


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