Verified Commit 40046f3c authored by Mateusz Żebrak's avatar Mateusz Żebrak
Browse files

Fix random error when Header cannot query_one HeaderTitle after pop_screen being called in tests

Seemed like pop_screen in some situations does not guarante that
we can update a reactive attribute right after it happens. If such a a
reactive attribute causes to query some elements on the screen
that should be visible again screen - widgets might be missing.

Related callstack:
```bash
  File "/builds/hive/clive/clive/__private/ui/transaction_summary/common.py", line 231, in __broadcast
    self.action_dashboard()
  File "/builds/hive/clive/clive/__private/ui/transaction_summary/common.py", line 208, in action_dashboard
    self.app.pop_screen_until(DashboardBase)
  File "/builds/hive/clive/clive/__private/ui/app.py", line 259, in pop_screen_until
    self.pop_screen()
  File "/builds/hive/clive/clive/__private/ui/app.py", line 243, in pop_screen
    return self.__update_screen(lambda: fun())
  File "/builds/hive/clive/clive/__private/ui/app.py", line 278, in __update_screen
    self.title = f"{self.__class__.__name__} ({self.screen.__class__.__name__})"
  File "/home/hived_admin/.cache/pypoetry/virtualenvs/clive-W0ktORSe-py3.10/lib/python3.10/site-packages/textual/reactive.py", line 276, in __set__
    self._check_watchers(obj, name, current_value)
  File "/home/hived_admin/.cache/pypoetry/virtualenvs/clive-W0ktORSe-py3.10/lib/python3.10/site-packages/textual/reactive.py", line 319, in _check_watchers
    invoke_watcher(reactable, callback, old_value, value)
  File "/home/hived_admin/.cache/pypoetry/virtualenvs/clive-W0ktORSe-py3.10/lib/python3.10/site-packages/textual/reactive.py", line 83, in invoke_watcher
    watch_result = cast(WatchCallbackNoArgsType, watch_function)()
  File "/home/hived_admin/.cache/pypoetry/virtualenvs/clive-W0ktORSe-py3.10/lib/python3.10/site-packages/textual/widgets/_header.py", line 196, in set_title
    self.query_one(HeaderTitle).text = self.screen_title
  File "/home/hived_admin/.cache/pypoetry/virtualenvs/clive-W0ktORSe-py3.10/lib/python3.10/site-packages/textual/dom.py", line 1260, in query_one
    return query.only_one() if expect_type is None else query.only_one(expect_type)
  File "/home/hived_admin/.cache/pypoetry/virtualenvs/clive-W0ktORSe-py3.10/lib/python3.10/site-packages/textual/css/query.py", line 255, in only_one
    self.first(expect_type) if expect_type is not None else self.first()
  File "/home/hived_admin/.cache/pypoetry/virtualenvs/clive-W0ktORSe-py3.10/lib/python3.10/site-packages/textual/css/query.py", line 226, in first
    raise NoMatches(f"No nodes match {self!r} on {self.node!r}")
textual.css.query.NoMatches: No nodes match <DOMQuery query='HeaderTitle'> on Header()
```

Example job: https://gitlab.syncad.com/hive/clive/-/jobs/1006471

Solution:
Do not query HeaderTitle (which is done internally by Textual),
but refer to the header title instance instead.
parent a7e888d5
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment