Conversation
Inside batch_update() property edits are deferred, but appending to a compound array property still swaps in the new child objects, so the freshly added shapes have no properties to read back yet. add_vline() and friends then fail with "unsupported operand type(s) for +=: 'NoneType' and 'str'" while appending " domain" to the axis reference, and a second add_shape()/add_annotation() in the same batch copies the first one as an empty object. Layout objects are structural additions like traces, and add_traces() already applies those immediately regardless of batch mode. Do the same here: add the objects and fix up their axis references with batch mode switched off, so only regular property edits stay batched. Closes plotly#4742
Contributor
|
Thanks for the PR! We'll take a look and follow up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Link to issue
Closes #4742
Description of change
Inside
batch_update()property edits are deferred until the context exits, but appending to a compound array property (fig.layout.shapes += (shape,)) still swaps in the new child objects right away. Those objects have no properties to read back until the batch is applied.add_vline(),add_hline(),add_vrect()andadd_hrect()read the shape they just added to append" domain"to its axis reference, which gives theTypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'from the issue. The same thing makes a secondadd_shape()/add_annotation()inside one batch copy the first object as{}, so it silently disappears.Adding layout objects is a structural change like adding traces, and
add_traces()already applies those immediately regardless of batch mode. This does the same for layout objects:_add_annotation_like()appends the object, and_process_multiple_axis_spanning_shapes()adds and fixes up the axis-spanning shapes, with batch mode switched off (new_batch_mode_disabled()context manager next tobatch_update()). Regular property edits in the batch are still deferred and sent in one update message as before.Demo
before:
after (same as without
batch_update()):Two shapes in one batch:
before:
after:
Testing strategy
test_add_axis_spanning_shape_in_batch_update(autoshapes tests) adds each of the four shapes, some with annotations, to a single plot, to one subplot and to all subplots, inside and outsidebatch_update(), and checks that the resulting shapes and annotations are identical.test_add_layout_objects_in_batch_update(figure messages tests) checks that shapes and annotations added inside a batch are there right away and go out as their own relayout messages, while a regular property assignment in the same batch is still deferred and sent in the single update message. All 13 new cases fail onmain. Runningtests/test_core,test_autoshapes,test_pxandtest_figure_factorywith and without the change gives the same set of other failures (Windowscp1252decoding intest_offline, statsmodels and scikit-image not installed here).Additional information (optional)
I kept the fix local to adding layout objects. Assigning a compound array property directly inside a batch (
fig.layout.shapes = [...]) still leaves the new children without readable properties until the batch is applied; changing that would touch howFigureWidgetbatches its messages, so I left it alone here.Guidelines