Skip to content

Commit

Permalink
Do no update objects inplace unless explicitly requested (#6055)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 15, 2023
1 parent ecaeb0f commit 8525759
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
17 changes: 3 additions & 14 deletions panel/pane/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,20 +682,9 @@ def _update_from_object(cls, object: Any, old_object: Any, was_internal: bool, i
old_object.object = object
else:
# Replace pane entirely
pane = panel(object, **{k: v for k, v in kwargs.items()
if k in pane_type.param})
if pane is object:
# If all watchers on the object are internal watchers
# we can make a clone of the object and update this
# clone going forward, otherwise we have replace the
# model entirely which is more expensive.
if not (custom_watchers or links):
pane = object.clone()
internal = True
else:
internal = False
else:
internal = object is not old_object
pane_params = {k: v for k, v in kwargs.items() if k in pane_type.param}
pane = panel(object, **pane_params)
internal = pane is not object
return pane, internal

def _update_inner(self, new_object: Any) -> None:
Expand Down
10 changes: 5 additions & 5 deletions panel/tests/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,20 +1315,20 @@ def view(a):

pane = panel(view)
inner_pane = pane._pane
assert inner_pane is not objs[0]
assert inner_pane is objs[0]
assert inner_pane.object is objs[0].object
assert pane._internal
assert not pane._internal

test.a = 1

assert pane._pane is inner_pane
assert pane._internal
assert pane._pane is not inner_pane
assert not pane._internal

objs[0].param.watch(print, ['object'])

test.a = 0

assert pane._pane is not inner_pane
assert pane._pane is inner_pane
assert not pane._internal


Expand Down

0 comments on commit 8525759

Please sign in to comment.