Skip to content

Commit

Permalink
Merge pull request jupyter-widgets#3486 from meeseeksmachine/auto-bac…
Browse files Browse the repository at this point in the history
…kport-of-pr-3484-on-7.x

Backport PR jupyter-widgets#3484 on branch 7.x (Check self.keys before accessing trait in set_state())
  • Loading branch information
jasongrout authored Jun 11, 2022
2 parents 32a2d68 + 4ec8dee commit 7665944
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ipywidgets/widgets/tests/test_set_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,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 ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,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

0 comments on commit 7665944

Please sign in to comment.