From 08d80b8ddc9ee77453c23d252bf87542e6dd257e Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 24 Nov 2026 13:06:24 +0100 Subject: [PATCH 1/2] fix: Let collect's partial results through the upstream awaiting check Skipping an operation whose upstream is awaiting also skipped every node downstream of collect, and refs reading it, until all of collect's inputs had settled, so the partial results collect exists for never reached them. Stop the upstream walk at collect nodes. Assisted-by: Claude Code:claude-opus-5-5 --- param/reactive.py | 18 +++++++++++++++++- tests/testreactive.py | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/param/reactive.py b/param/reactive.py index 876bdf6b6..99e456c30 100644 --- a/param/reactive.py +++ b/param/reactive.py @@ -2707,8 +2707,24 @@ def _upstream_awaiting(node): last value, so readers must look past it to avoid computing with it. Async refs are not considered: they write their value before they settle, so the update that delivers the value would be skipped. + The walk stops at ``collect`` nodes, which report partial results + while their inputs are still pending. """ - return any(n._awaiting for n in _unmirror(node)._upstream()) + seen: set[int] = set() + stack = [_unmirror(node)] + while stack: + upstream = stack.pop() + if (id_node := id(upstream)) in seen: + continue + seen.add(id_node) + if upstream._awaiting: + return True + operation = upstream._operation + if operation is not None and operation['fn'] is _collect_marker: + continue + stack.extend(upstream._direct_inputs()) + stack.extend(upstream._ref_inputs()) + return False def _settle_state(node): diff --git a/tests/testreactive.py b/tests/testreactive.py index 89d3ae79a..84f9d9185 100644 --- a/tests/testreactive.py +++ b/tests/testreactive.py @@ -6629,6 +6629,28 @@ async def delayed(v, delay): ) assert not collected.rx.awaiting + async def test_reactive_collect_partial_results_reach_downstream_nodes_and_refs(self): + async def delayed(v, delay): + await asyncio.sleep(delay) + return v + + class Members(param.Parameterized): + values = param.List(default=[], allow_refs=True) + + a = rx(1).rx.pipe(delayed, delay=0.05) + b = rx(2).rx.pipe(delayed, delay=0.25) + listed = collect(a, b).args.rx.pipe(list) + members = Members(values=listed) + + node_values, param_values = [], [] + listed.rx.watch(node_values.append) + members.param.watch(lambda e: param_values.append(e.new), 'values') + listed.rx.value + + expected = [[1, param.Undefined], [1, 2]] + await async_wait_until(lambda: node_values == expected[:1] and param_values == expected[:1], interval=10) + await async_wait_until(lambda: node_values == expected and param_values == expected, interval=10) + def test_reactive_collect_returns_a_namedtuple_of_args_and_kwargs(self): a, b = rx(1), rx(2) collected = collect(a, b, c=rx(3)) From 51d3f2bf56c08117b977276b6c465b2df27b8ea9 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 24 Nov 2026 14:40:06 +0100 Subject: [PATCH 2/2] Apply suggestion from @hoxbro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon Høxbro Hansen --- param/reactive.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/param/reactive.py b/param/reactive.py index 99e456c30..22c1e741a 100644 --- a/param/reactive.py +++ b/param/reactive.py @@ -2716,9 +2716,9 @@ def _upstream_awaiting(node): upstream = stack.pop() if (id_node := id(upstream)) in seen: continue - seen.add(id_node) if upstream._awaiting: return True + seen.add(id_node) operation = upstream._operation if operation is not None and operation['fn'] is _collect_marker: continue