Skip to content

Commit

Permalink
Chekc self.keys before trait_metadata in set_state
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao Chen committed Jun 10, 2022
1 parent d1491e9 commit eddfdc6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ class ValueWidget(Widget):
assert widget.value == 1

widget._send = mock.MagicMock()
# this mimics a value coming from the front end
widget.set_state({'value': 42})
# this mimics a state coming from the front end
widget.set_state({'value': 42, 'unexpected_field': 43})
assert widget.value == 42

# we expect this to be echoed
Expand Down
4 changes: 2 additions & 2 deletions python/ipywidgets/ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ def set_state(self, sync_data):
# Send an echo update message immediately
if JUPYTER_WIDGETS_ECHO:
echo_state = {}
for attr,value in sync_data.items():
if self.trait_metadata(attr, 'echo_update', default=True):
for attr, value in sync_data.items():
if attr in self.keys and self.trait_metadata(attr, 'echo_update', default=True):
echo_state[attr] = value
if echo_state:
echo_state, echo_buffer_paths, echo_buffers = _remove_buffers(echo_state)
Expand Down
1 change: 1 addition & 0 deletions python/jupyterlab_widgets/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ export class WidgetManager extends LabWidgetManager {
this._context = context;

context.sessionContext.kernelChanged.connect((sender, args) => {
console.log('kernel changed');
this._handleKernelChanged(args);
});

Expand Down

0 comments on commit eddfdc6

Please sign in to comment.