From ac699c4b6543954ce150be1db9ff17523873dc9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Rudnicki?= Date: Fri, 26 Jul 2024 15:25:01 +0200 Subject: [PATCH] Fix sporadic NoMatches error reported from Header on app shutdown During application shutdown, particularly when running via `App.run_test()`, it seems that the Header's watcher callback on `title` or `sub_title` is called while the Header's children, such as the `HeaderTitle`, are already unmounted. This results in a `NoMatches` error being reported. We fix this by ignoring the `NoMatches` error, like we did with `NoScreen` in the recent "hardedning" commit 604b04db2. --- src/textual/widgets/_header.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/textual/widgets/_header.py b/src/textual/widgets/_header.py index 3505514813..152ad31ef4 100644 --- a/src/textual/widgets/_header.py +++ b/src/textual/widgets/_header.py @@ -7,6 +7,7 @@ from rich.text import Text from ..app import RenderResult +from ..css.query import NoMatches from ..dom import NoScreen from ..events import Click, Mount from ..reactive import Reactive @@ -216,13 +217,13 @@ def _on_mount(self, _: Mount) -> None: async def set_title() -> None: try: self.query_one(HeaderTitle).text = self.screen_title - except NoScreen: + except (NoScreen, NoMatches): pass async def set_sub_title() -> None: try: self.query_one(HeaderTitle).sub_text = self.screen_sub_title - except NoScreen: + except (NoScreen, NoMatches): pass self.watch(self.app, "title", set_title)