Skip to content

Commit

Permalink
fix: do not hold sync during set_state
Browse files Browse the repository at this point in the history
If we do, we get very inconsistent behaviour, see jupyter-widgets#3635 for more
details and jupyter-widgets#3271 for the reasons to implement this.
  • Loading branch information
maartenbreddels committed Nov 29, 2022
1 parent 3ce6472 commit 05fc32f
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 @@ -616,7 +616,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 05fc32f

Please sign in to comment.