on_mount runs without composed children if the widget is removed before it starts: intended?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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) |
- Lingua principale
- Python
- Stelle
- 37.7k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Textualize/textual
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6790 · 2 commenti ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Textualize/textual#6789 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6787 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6782 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
Textualize/textual#6778 · 1 commento ·
Tutte le issue di Textualize/textual
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mohanraj00/entelos#200 ·
I maintainer di solito rispondono entro 1 giorno
-
Dead url in mise.tomlAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
-
sweep
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
bketelsen/truenas-mcp#77 ·
I maintainer di solito rispondono entro 1 giorno
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
sandbox-quantum/switch#2163 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
openedx/xblock-lti-consumer#765 ·
I maintainer di solito rispondono entro 1 giorno