Error raised when an app is terminated with an empty SelectionList
.
#3559
-
Hi! I was writing a simple tool to add/delete kafka topics with textual. Can you please help me...? Error MessageFull Error MessageTraceback (most recent call last): File ".tox/dev/lib/python3.10/site-packages/textual/message_pump.py", line 536, in _process_messages_loop await self._dispatch_message(message) File ".tox/dev/lib/python3.10/site-packages/textual/message_pump.py", line 599, in _dispatch_message await self._on_message(message) File ".tox/dev/lib/python3.10/site-packages/textual/message_pump.py", line 687, in _on_message await invoke(method, message) File ".tox/dev/lib/python3.10/site-packages/textual/_callback.py", line 74, in invoke return await _invoke(callback, *params) File ".tox/dev/lib/python3.10/site-packages/textual/_callback.py", line 34, in _invoke result = callback(*params[:parameter_count]) File ".tox/dev/lib/python3.10/site-packages/textual/widgets/_selection_list.py", line 579, in _on_option_list_option_highlighted self.post_message(self.SelectionHighlighted(self, event.option_index)) File ".tox/dev/lib/python3.10/site-packages/textual/widgets/_selection_list.py", line 172, in __init__ ] = selection_list.get_option_at_index(index) File ".tox/dev/lib/python3.10/site-packages/textual/widgets/_selection_list.py", line 603, in get_option_at_index return cast("Selection[SelectionType]", super().get_option_at_index(index)) File "/.tox/dev/lib/python3.10/site-packages/textual/widgets/_option_list.py", line 836, in get_option_at_index raise OptionDoesNotExist( textual.widgets._option_list.OptionDoesNotExist: There is no option with an index of 0
Reproduce Error
Here is the code snippet of very simplified app that can reproduce the error: empty_selection_list_error.py
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
This isn't an answer to the question, and that's quite a bit of code to wade through to be able to help (although it seems clear whatever is going on is happening around existing_options = [option for option in self.options._option_ids]
|
Beta Was this translation helpful? Give feedback.
-
I suspect the problem is that your |
Beta Was this translation helpful? Give feedback.
-
I am currently using a workaround to replace This seems like to solve the problem but I am not sure if it is a good practice to destroy and create a widget instance so frequently.... |
Beta Was this translation helpful? Give feedback.
While checking back on my outstanding issues, I found #3560 which I raised off the back off this discussion. I think this problem is resolved in the latest version of Textual, though I confess my memory is a bit hazy on the specifics!