Skip to content

Commit

Permalink
Merge pull request #3642 from maartenbreddels/fix_no_hold_sync_during…
Browse files Browse the repository at this point in the history
…_set_state

fix: do not hold sync during set_state
  • Loading branch information
jasongrout authored Dec 6, 2022
2 parents 2af0cc4 + e6199d9 commit f37bb30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,13 @@ def _propagate_value(self, change):
msg = {'method': 'echo_update', 'state': {'value': 42.0}, 'buffer_paths': []}
call42 = mock.call(msg, buffers=[])

msg = {'method': 'update', 'state': {'value': 2.0, 'other': 11.0}, 'buffer_paths': []}
msg = {'method': 'update', 'state': {'value': 2.0}, 'buffer_paths': []}
call2 = mock.call(msg, buffers=[])

calls = [call42, call2] if echo else [call2]
msg = {'method': 'update', 'state': {'other': 11.0}, 'buffer_paths': []}
call11 = mock.call(msg, buffers=[])

calls = [call42, call2, call11] if echo else [call2, call11]
widget._send.assert_has_calls(calls)


Expand Down
2 changes: 1 addition & 1 deletion python/ipywidgets/ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def set_state(self, sync_data):
# The order of these context managers is important. Properties must
# be locked when the hold_trait_notification context manager is
# released and notifications are fired.
with self.hold_sync(), self._lock_property(**sync_data), self.hold_trait_notifications():
with self._lock_property(**sync_data), self.hold_trait_notifications():
for name in sync_data:
if name in self.keys:
from_json = self.trait_metadata(name, 'from_json',
Expand Down

0 comments on commit f37bb30

Please sign in to comment.