{"record":{"id":"45c820d63c76381b","repo":"Textualize/textual","slug":"can-t-clear-selection-if-allow-blank-is-set-to-fal","errorCode":null,"errorMessage":"Can't clear selection if allow_blank is set to False.","messagePattern":"Can't clear selection if allow_blank is set to False\\.","errorType":"exception","errorClass":"InvalidSelectValueError","httpStatus":null,"severity":"error","filePath":"src/textual/widgets/_select.py","lineNumber":705,"sourceCode":"\n    def is_blank(self) -> bool:\n        \"\"\"Indicates whether this `Select` is blank or not.\n\n        Returns:\n            True if the selection is blank, False otherwise.\n        \"\"\"\n        return self.value == self.NULL\n\n    def clear(self) -> None:\n        \"\"\"Clear the selection if `allow_blank` is `True`.\n\n        Raises:\n            InvalidSelectValueError: If `allow_blank` is set to `False`.\n        \"\"\"\n        try:\n            self.value = self.NULL\n        except InvalidSelectValueError:\n            raise InvalidSelectValueError(\n                \"Can't clear selection if allow_blank is set to False.\"\n            ) from None\n\n    def _watch_prompt(self, prompt: str) -> None:\n        if not self.is_mounted:\n            return\n        select_current = self.query_one(SelectCurrent)\n        select_current.placeholder = prompt\n        if not self._allow_blank:\n            return\n        if self.value == self.NULL:\n            select_current.update(self.NULL)\n        option_list = self.query_one(SelectOverlay)\n        option_list.replace_option_prompt_at_index(0, Text(prompt, style=\"dim\"))\n","sourceCodeStart":687,"sourceCodeEnd":720,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widgets/_select.py#L687-L720","documentation":"Raised by Select.clear() when allow_blank is False. clear() assigns the internal NULL sentinel value; the value validator rejects it because blank is not among the legal values, and the error is re-raised with a clearer message.","triggerScenarios":"Creating Select([...], allow_blank=False) and later calling select.clear(), often in a form-reset handler.","commonSituations":"Form reset buttons, clearing selection after data reload, or generic reset code that assumes every Select can be cleared.","solutions":["Construct the Select with allow_blank=True if you need to clear it.","Guard: only call clear() when select.allow_blank.","Reset to a default option value instead of clearing: select.value = default_value."],"exampleFix":"# before\nSelect(options, allow_blank=False)\n# ...\nselect.clear()  # raises\n# after\nSelect(options, allow_blank=True)\n# ...\nselect.clear()","handlingStrategy":"validation","validationCode":"if select.allow_blank:\n    select.clear()\nelse:\n    select.value = first_option_value","typeGuard":null,"tryCatchPattern":"try:\n    select.clear()\nexcept InvalidSelectValueError:\n    pass  # allow_blank is False","preventionTips":["Create Selects with allow_blank=True if resets are needed","Centralize form-reset logic that respects allow_blank"],"tags":["select","allow-blank","textual","clear"],"backgroundTag":"clear-disallowed-state","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}