Textualize/textual · error · OptionDoesNotExist
There is no option with an ID of {option_id!r}
Error message
There is no option with an ID of {option_id!r} What it means
Raised by OptionList.get_option when no option with the supplied id exists. The widget looks up ids in an internal _id_to_option dict built only from Options that were given an explicit id; a KeyError is converted to OptionDoesNotExist.
Source
Thrown at src/textual/widgets/_option_list.py:444
self.add_options([option])
return self
def get_option(self, option_id: str) -> Option:
"""Get the option with the given ID.
Args:
option_id: The ID of the option to get.
Returns:
The option with the ID.
Raises:
OptionDoesNotExist: If no option has the given ID.
"""
try:
return self._id_to_option[option_id]
except KeyError:
raise OptionDoesNotExist(
f"There is no option with an ID of {option_id!r}"
) from None
def get_option_index(self, option_id: str) -> int:
"""Get the index (offset in `self.options`) of the option with the given ID.
Args:
option_id: The ID of the option to get the index of.
Returns:
The index of the item with the given ID.
Raises:
OptionDoesNotExist: If no option has the given ID.
"""
option = self.get_option(option_id)
return self._option_to_index[option]
View on GitHub (pinned to 06dbeef4bb)
Solutions
- Check membership first with `option_id in option_list._id_to_option` or wrap in try/except OptionDoesNotExist.
- Verify the option was created with an explicit unique id: Option('prompt', id='my-id').
- Re-check ids after set_options/clear_options, which invalidate previously valid ids.
Example fix
# before
option = option_list.get_option(user_choice)
# after
from textual.widgets.option_list import OptionDoesNotExist
try:
option = option_list.get_option(user_choice)
except OptionDoesNotExist:
option = None Defensive patterns
Strategy: try-catch
Try / catch
from textual.widgets.option_list import OptionDoesNotExist
try:
option = option_list.get_option(option_id)
except OptionDoesNotExist:
... Prevention
- Give options explicit ids at creation
- Revalidate ids after set_options/clear_options
- Wrap lookups driven by user input in try/except OptionDoesNotExist
When it happens
Trigger: Calling get_option('missing'), get_option_index('missing'), or remove_option('missing') with an id that was never added (or was removed earlier). Also calling get_option with an option's prompt text instead of its id.
Common situations: Stale ids after the option list was rebuilt via set_options/clear_options, typos in ids, or assuming options without explicit ids still have ids (auto options have id None and are not in the map).
Related errors
- Unable to add {option!r} due to duplicate ID
- There is no option with an index of {index}
- Unable to remove; there is no option at index {index}
- Can't animate attribute {attribute!r} on {obj!r}; attribute
- Don't know how to animate {value!r}; Can only animate <int>,
AI-assisted analysis of Textualize/textual@06dbeef4bb (2026-08-27).
Data as JSON: /api/errors/f272ff3fa038bee1.
Report an issue: GitHub.