on_mount runs without composed children if the widget is removed before it starts: intended?
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
調査の方向性
Start by running the supplied reproduction with app.run_test() and trace the lifecycle through Widget.mount and MessagePump._pre_process, the entry points named in the report. Compare the test-harness case with removal under a real App.run(). Done means the behavior is defined and consistent: on_mount should not run with composed children missing, and a regression test covers the removal timing.
索引モデルが issue の本文から書いたものです。
説明
Hi! I work on an app built on Textual, and our test suite fails now and then on a slow CI runner with NoMatches raised from an on_mount. I narrowed it down to a few lines with no app code of ours. If a widget is removed before it has started, on_mount still runs, but its children were never mounted, so a query_one for a child from its own compose fails and the app exits.
This runs as it is:
import asyncio
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Label
class Card(Vertical):
def compose(self) -> ComposeResult:
yield Label("title", id="title")
def on_mount(self) -> None:
print("on_mount: children =", list(self.children))
self.query_one("#title", Label).update("mounted")
async def main() -> None:
app = App()
async with app.run_test() as pilot:
card = Card()
app.mount(card)
card.remove()
await pilot.pause()
asyncio.run(main())
Output on 8.2.8 and on main at 5e5b7ef:
on_mount: children = []
...
textual.css.query.NoMatches: No nodes match '#title' on Card()
What I think is happening
Widget.mountreturns early when the widget is_closingor_pruning, so the children fromcomposeare dropped without an error.MessagePump._pre_processthen dispatchesMountanyway, and the exception fromon_mountgoes toApp._handle_exception, which exits the app.
Where it does and doesn't happen, in the cases I tried
- Removing the widget's parent straight after mounting, or calling
app.exit()straight after mounting, fail the same way underrun_test. - Under a real
App.run()I couldn't make it crash. Mounting and then removing from a timer, a worker orcall_laterrunson_mountwith_pruningtrue, but the children are there. So it may only be reachable with the test harness's timing, or on a machine slower than mine.
Is on_mount meant to run in this case? I'd have expected to be able to rely on the children from compose being there in on_mount, so my preference would be for Mount to be skipped once the widget is being removed, but there may be a reason for it that I'm missing. For now we're guarding the lookups in our own widgets, and I wanted to check before relying on that as the long-term answer.
I searched the open and closed issues for NoMatches with on_mount and removal, and didn't find this one.
Textual Diagnostics
Versions
| Name | Value |
|---|---|
| Textual | 8.2.8 |
| Rich | 15.0.0 |
Python
| Name | Value |
|---|---|
| Version | 3.14.10 |
| Implementation | CPython |
| Compiler | Clang 23.1.3 |
Operating System
| Name | Value |
|---|---|
| System | Darwin |
| Release | 24.6.0 |
| Version | Darwin Kernel Version 24.6.0: Tue Jul 21 20:51:25 PDT 2026; root:xnu-11417.140.69.711.44~1/RELEASE_ARM64_T8132 |
Terminal
| Name | Value |
|---|---|
| Terminal Application | rex (0.0.1793072516-g956d74) |
- 主要言語
- Python
- スター
- 37.7k
- フォーク
- 1.5k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Textualize/textual のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6790 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
Textualize/textual#6789 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6787 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6782 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
Textualize/textual#6778 · コメント 1 件 ·
Textualize/textual の issue をすべて見る
似ている issue
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskオープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
sandbox-quantum/switch#2163 ·
メンテナーはふだん 1 日以内に返信
-
bug pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pydantic/pydantic-ai#13939 ·
メンテナーはふだん 1 日以内に返信
-
priority: low python
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
LearningCircuit/local-deep-research#8849 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
francescopace/espectre#223 ·
メンテナーはふだん 3 日以内に返信
-
good first issue Status: Triaged
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
canonical/imagecraft#538 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信