{"record":{"id":"37244441ea4b3409","repo":"Textualize/textual","slug":"select-options-cannot-be-empty-if-selection-can-t","errorCode":null,"errorMessage":"Select options cannot be empty if selection can't be blank.","messagePattern":"Select options cannot be empty if selection can't be blank\\.","errorType":"exception","errorClass":"EmptySelectError","httpStatus":null,"severity":"error","filePath":"src/textual/widgets/_select.py","lineNumber":530,"sourceCode":"        if isinstance(value, NoSelection):\n            return None\n        return value\n\n    def _setup_variables_for_options(\n        self,\n        options: Iterable[tuple[RenderableType, SelectType]],\n    ) -> None:\n        \"\"\"Setup function for the auxiliary variables related to options.\n\n        This method sets up `self._options` and `self._legal_values`.\n        \"\"\"\n        self._options: list[tuple[RenderableType, SelectType | NoSelection]] = []\n        if self._allow_blank:\n            self._options.append((\"\", self.NULL))\n        self._options.extend(options)\n\n        if not self._options:\n            raise EmptySelectError(\n                \"Select options cannot be empty if selection can't be blank.\"\n            )\n\n        self._legal_values: set[SelectType | NoSelection] = {\n            value for _, value in self._options\n        }\n\n    def _setup_options_renderables(self) -> None:\n        \"\"\"Sets up the `Option` renderables associated with the `Select` options.\"\"\"\n        options: list[Option] = [\n            (\n                Option(Text(self.prompt, style=\"dim\"))\n                if value == self.NULL\n                else Option(prompt)\n            )\n            for prompt, value in self._options\n        ]\n","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widgets/_select.py#L512-L548","documentation":"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.","triggerScenarios":"Select([], allow_blank=False), Select(options=[], prompt='Pick') with default allow_blank=False, or set_options([]) on a Select created with allow_blank=False.","commonSituations":"Building a Select from a dynamic query that returns zero results (empty DB/api response), or filtering options down to nothing before rendering.","solutions":["Set allow_blank=True when the option source may be empty.","Guard before construction: skip creating the Select or show a placeholder message when options is empty.","Feed a non-empty default option list."],"exampleFix":"# before\nSelect(options(), allow_blank=False)  # options() may return []\n# after\nif not options():\n    mount(Label('No options available'))\nelse:\n    mount(Select(options(), allow_blank=False))","handlingStrategy":"validation","validationCode":"opts = list(options)\nif not opts:\n    opts = [('', None)]  # or skip mounting\nselect = Select(opts, allow_blank=bool(opts) or allow_blank)","typeGuard":null,"tryCatchPattern":"from textual.widgets.select import EmptySelectError\ntry:\n    Select([], allow_blank=False)\nexcept EmptySelectError:\n    ...","preventionTips":["Default to allow_blank=True when data may be empty","Gate widget creation on non-empty option sources"],"tags":["select","empty-options","textual","validation"],"backgroundTag":"empty-options-validation","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}