holoviz / holoviz/param

Control event order with nested Parameterized

Open
#1,056 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
521
Forks
86
Avg merge
1d 13h
Merged PRs (30d)
35

Description

#### ALL software version info

Software Version Info

```plaintext
param==2.2.0
python==3.12.9
```

#### Description of expected behavior and the observed behavior

The precedence level doesn’t seem to work across different objects, but the order of events in my example does follow a pattern that must be defined somewhere (and so is hopefully adjustable).

The events for the nested objects are always executed in the order in which the objects were created, finally the events from the container class are executed according to precedence.

I expect the event order to respect the precedence levels set.

#### Complete, minimal, self-contained example code that reproduces the issue

```python
import param
import numpy as np

class Sub(param.Parameterized):

data = param.Number(allow_refs=True)

def __init__(self, **params):
super().__init__(**params)
self.precedence = np.random.randint(5, 10)
self.param.watch(self.data_changed, "data", precedence=self.precedence)

def data_changed(self, event):
print(f"[{self.name}] ({self.precedence})")

class Test(param.Parameterized):

my_list = param.List(item_type = Sub)

data = param.Number()

def __init__(self, **params):
super().__init__(**params)
self.param.watch(self.data_changed, "data", precedence=0)
self.param.watch(self.data_really_changed, "data", precedence=1)

def make_sub(self):
sub = Sub(data = self.param["data"])
self.param.update(
my_list = self.my_list + [sub]
)

def data_changed(self, event):
print(f"[{self.name}] (0)")

def data_really_changed(self, event):
print(f"[{self.name}] (1)")

test = Test()

test.make_sub()
test.make_sub()
test.make_sub()

test.data = 5

>>> [Sub00057] (6)
>>> [Sub00058] (8)
>>> [Sub00059] (5)
>>> [Test00056] (0)
>>> [Test00056] (1)

```

But I expect to first execute the events linked to Test00056 object (with a lower precedence) and then the events linked to the Sub000XX instances.

#### Other info

I wasn't sure if this was a bug, but according to people on the discourse it is. See here: https://discourse.holoviz.org/t/control-event-order-with-nested-parameterized/8579

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.