Skip to content

Commit

Permalink
fix: Don't error if data does not have name attribute (#7655)
Browse files Browse the repository at this point in the history
* fix: Don't error if data does not have name attribute

* Add test

* rename to not error?
  • Loading branch information
hoxbro authored Jan 22, 2025
1 parent dad982b commit 663df35
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion panel/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ def _update_model(
from .io.datamodel import create_linked_datamodel
old = getattr(model.data, prop)
if isinstance(old, list):
mapping = {o.name: o for o in old}
mapping = {getattr(o, "name", o): o for o in old}
vals = []
for vs in v:
if (vname:=f"{root.ref['id']}-{id(vs)}") in mapping:
Expand Down
12 changes: 12 additions & 0 deletions panel/tests/test_reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,15 @@ def test_reactive_design_stylesheets_update(document, comm):

assert len(model.stylesheets) == 5
assert model.stylesheets[-1] == widget.stylesheets[0]


def test_reactive_attribute_no_name(document, comm):
# Regression: https://github.com/holoviz/panel/pull/7655
class CustomComponent2(ReactiveHTML):
groups = param.ListSelector(default=["A"], objects=["A", "B"])
_scripts = {"groups": "console.log(data.groups)"}

component = CustomComponent2()
component.get_root(document, comm)
# Should not error out
component.groups = []

0 comments on commit 663df35

Please # to comment.