Skip to content

Control event order with nested Parameterized #1056

@bertcoerver

Description

@bertcoerver

ALL software version info

Software Version Info
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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions