Fix SelectCurrent.update() crash when called before mount (#6581) - #6680
rudrakumar07 wants to merge 1 commit into
Conversation
Guard the query_one("#label") call in SelectCurrent.update() with
an is_mounted check. When update() is called before the widget is
mounted (e.g., from _watch_value during initialization), the #label
child doesn't exist yet, causing a NoMatches crash.
Fixes Textualize#6581
Phantom8420
left a comment
There was a problem hiding this comment.
The fix is correct for the crash: SelectCurrent.update() is reached from Select._watch_value before Select itself has finished mounting (the outer query_one(SelectCurrent) in _watch_value already succeeds against the composed-but-not-yet-mounted child, so SelectCurrent.update()'s own query_one("#label") is what blows up). Guarding with is_mounted avoids that without changing behavior once mounted.
I traced through whether the guard just swallows the update rather than deferring it: Select._on_mount calls _init_selected_option(self._value), which reassigns self.value and re-triggers _watch_value → select_current.update(...) after Select (and its already-composed SelectCurrent child) are mounted. So the label does get set correctly once mounting completes — this isn't silently dropping the initial value, just deferring it to the point where the query is safe.
Two things worth adding before merge:
- No regression test. Something that constructs/mounts a
Selectwith an initialvalueset pre-mount (or otherwise exercises the pre-mountupdate()path) and asserts no crash, plus that the label ends up correct post-mount, would pin this. - CHANGELOG.md entry — the PR checklist requires one; this PR doesn't have it.
Fixes #6581.
SelectCurrent.update()queried#labelbefore the widget was mounted, causing a crash. Addedif self.is_mounted:guard around thequery_onecall, matching the existing pattern in_watch_prompt.