Textualize/textual · error · InvalidSelectValueError
Can't clear selection if allow_blank is set to False.
Error message
Can't clear selection if allow_blank is set to False.
What it means
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.
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.
Example fix
# before Select(options, allow_blank=False) # ... select.clear() # raises # after Select(options, allow_blank=True) # ... select.clear()
Defensive patterns
Strategy: validation
Validate before calling
if select.allow_blank:
select.clear()
else:
select.value = first_option_value Try / catch
try:
select.clear()
except InvalidSelectValueError:
pass # allow_blank is False Prevention
- Create Selects with allow_blank=True if resets are needed
- Centralize form-reset logic that respects allow_blank
When it happens
Trigger: Creating Select([...], allow_blank=False) and later calling select.clear(), often in a form-reset handler.
Common situations: Form reset buttons, clearing selection after data reload, or generic reset code that assumes every Select can be cleared.
Related errors
- Illegal select value
- Select options cannot be empty if selection can't be blank.
- A Reactive class is required; for example: MyApp.theme
- A widget can't be its own parent
- add_mode() must be called with a Screen type, not an…
AI-assisted analysis of Textualize/textual@06dbeef4bb (2026-08-27).
Data as JSON: /api/errors/45c820d63c76381b.
Report an issue: GitHub.
Appendix: source
Thrown at src/textual/widgets/_select.py:705
def is_blank(self) -> bool:
"""Indicates whether this `Select` is blank or not.
Returns:
True if the selection is blank, False otherwise.
"""
return self.value == self.NULL
def clear(self) -> None:
"""Clear the selection if `allow_blank` is `True`.
Raises:
InvalidSelectValueError: If `allow_blank` is set to `False`.
"""
try:
self.value = self.NULL
except InvalidSelectValueError:
raise InvalidSelectValueError(
"Can't clear selection if allow_blank is set to False."
) from None
def _watch_prompt(self, prompt: str) -> None:
if not self.is_mounted:
return
select_current = self.query_one(SelectCurrent)
select_current.placeholder = prompt
if not self._allow_blank:
return
if self.value == self.NULL:
select_current.update(self.NULL)
option_list = self.query_one(SelectOverlay)
option_list.replace_option_prompt_at_index(0, Text(prompt, style="dim"))
View on GitHub (pinned to 06dbeef4bb)