Skip to content

Fix SelectCurrent.update() crash when called before mount (#6581) - #6680

Open
rudrakumar07 wants to merge 1 commit into
Textualize:mainfrom
rudrakumar07:fix-select-update-before-mount
Open

rudrakumar07 wants to merge 1 commit into
Textualize:mainfrom
rudrakumar07:fix-select-update-before-mount

Conversation

@rudrakumar07

Copy link
Copy Markdown

Fixes #6581.

SelectCurrent.update() queried #label before the widget was mounted, causing a crash. Added if self.is_mounted: guard around the query_one call, matching the existing pattern in _watch_prompt.

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 Phantom8420 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. No regression test. Something that constructs/mounts a Select with an initial value set pre-mount (or otherwise exercises the pre-mount update() path) and asserts no crash, plus that the label ends up correct post-mount, would pin this.
  2. CHANGELOG.md entry — the PR checklist requires one; this PR doesn't have it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Select can crash during mount: SelectCurrent.update() queries #label before it is mounted (NoMatches)

2 participants