Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue 1581 #1584

Merged
merged 3 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def _update_widgets(self, *events):
parameters = [] if event.new == [] else event.new

if parameters != [] and parameters != self.parameters:
self.parameters = parameters
if not self.parameters:
self.parameters = parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does not seem correct to me, but I can see how the previous logic was incorrect too. Will keep your test though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

return

for cb in list(self._callbacks):
Expand Down
31 changes: 31 additions & 0 deletions panel/tests/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,3 +1097,34 @@ class Test(param.Parameterized):

assert test.a == 2
del os.environ['PARAM_JSON_INIT']

def test_change_object_and_keep_parameters():
"""Test that https://github.com/holoviz/panel/issues/1581 is solved"""
# Given
class TextModel(param.Parameterized):
text = param.String()
param2 = param.String()

class TextView(param.Parameterized):
text = param.ClassSelector(class_=TextModel)
text_pane = param.Parameter()

def __init__(self, **params):
params["text"] = TextModel(text="Original Text")
super().__init__(**params)

self.text_pane = Param(
self.text, parameters=["text"]
)

@param.depends("text", watch=True)
def _update_text_pane(self, *_):
self.text_pane.object = self.text

view = TextView()
assert view.text_pane.parameters==["text"]

# When
view.text = TextModel(text="New TextModel")
# Then
assert view.text_pane.parameters==["text"]