Repository navigation
Description
Hi! I hit this while writing tests that record the order of watcher calls. Reactive._compute loops over obj._reactives.keys() & obj._computes, a set of strings, so the order of the computes, and of the watchers they trigger, depends on string hashing, which Python randomises per process.
import asyncio
import textual
from textual.app import App
from textual.reactive import reactive
class ComputeApp(App):
value = reactive(0)
alpha = reactive(0)
beta = reactive(0)
gamma = reactive(0)
delta = reactive(0)
def __init__(self) -> None:
super().__init__()
self.calls: list[str] = []
def compute_alpha(self) -> int:
return self.value + 1
def compute_beta(self) -> int:
return self.value + 2
def compute_gamma(self) -> int:
return self.value + 3
def compute_delta(self) -> int:
return self.value + 4
def watch_alpha(self) -> None:
self.calls.append("alpha")
def watch_beta(self) -> None:
self.calls.append("beta")
def watch_gamma(self) -> None:
self.calls.append("gamma")
def watch_delta(self) -> None:
self.calls.append("delta")
async def main() -> None:
app = ComputeApp()
async with app.run_test() as pilot:
app.calls.clear()
app.value = 10
await pilot.pause()
print(app.calls)
asyncio.run(main())Run five times with different PYTHONHASHSEED values, on main (5e5b7ef), Python 3.13:
PYTHONHASHSEED=0: ['alpha', 'delta', 'beta', 'gamma']
PYTHONHASHSEED=1: ['beta', 'delta', 'gamma', 'alpha']
PYTHONHASHSEED=2: ['delta', 'gamma', 'alpha', 'beta']
PYTHONHASHSEED=3: ['gamma', 'beta', 'delta', 'alpha']
PYTHONHASHSEED=4: ['gamma', 'alpha', 'beta', 'delta']
8.2.7 gives a different mix for the same seeds. Without PYTHONHASHSEED set, the order changes from run to run.
The values are right either way, since reading a computed reactive computes it. Only the order of the watchers moves. I expected the same order on every run. A one-line fix is to sort the names in _compute, which makes the order alphabetical. Declaration order would be nicer, but it would mean walking every reactive on each change, so I went for sorting. Happy to do it the other way if you prefer.
Activity
github-actions commentedon Nov 13, 2026
We found the following entries in the FAQ which you may find helpful:
Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.
This project is developed and maintained by Will McGugan. Consider sponsoring Will's work on this project (and others).
This is an automated reply, generated by FAQtory
fix: give computed reactive watchers a deterministic invocation order (…
fix: give computed reactive watchers a deterministic invocation order (…
AdityaSreevatsaK commentedon Nov 18, 2026
Hi, I've implemented a fix for the nondeterministic watcher ordering reported here, including a regression test and changelog entry.
The changes are available here:
https://github.com/AdityaSreevatsaK/textual/tree/fix/6790-computed-reactive-order
I attempted to open a PR, but repository settings restrict PR creation to collaborators.
Would a maintainer be willing to review the changes or advise how external contributions should be submitted?
Thanks!