Add "widget_id" filter to "request_states" message, fixing + refactoring some CI #3833
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation of motivation
There is a bug in iPyWidgets state handling that happened quite frequently: If the
comm
target is already closed (when the widget is closed/deleted) before the frontend sends therequest_state
, Jupyter kernel swallows therequest_state
and does nothing (as the comm target does not exist), leading to the frontend thinking backend hangs. As a result, we need a source of truth for widget state when a widget is closed, and Widget Manager is currently the best source of truth since it have all the widget states.In order to solve the bug, the frontend can now ask Widget for the state with
request_states
. We do not want to send back the entire chunk of all widget states when we only need one state, we added the filter forrequest_states
. This will send back the state for a specific widget frontend is requesting, and if the response coming back is an empty dictionary frontend knows the widget doesn't exist any more. This solves the bug I mentioned above.Testing fixes
The testing pipeline's
DummyComm
have defaultcomm_id
, but widgets'model_id
is set to be itsself.comm.comm_id
. This means all widgets created in test environment have same model_id. Due to the way we set-up_instances
(_instances[self.model_id] = self
), that effectively means we only have 1 active widget available. This is fine in most cases, but in our case we do need different widgets co-exist for filtering verification. Hence, not thecomm_id
is randomly generated.