Repository navigation
Conversation
…ad of hanging A per-point array of color strings (e.g. ipv.scatter(x, y, z, color=['tomato', 'seagreen'])) makes ipyvolume's color serializer infinite-loop the first time the widget's state is serialized, freezing the whole Shiny process with no error. Reject string-dtype (and str-valued object) arrays on Scatter.color, Scatter.color_selected, and Mesh.color during coercion with a TypeError that names the trait and points to the working alternatives (a single color, or numeric data with a colormap). Scalar string colors like color='red' are unaffected.
✅ Deploy Preview for shinywidgets canceled.
|
There was a problem hiding this comment.
🟡 Changes recommended
A critical issue remains: rejected scatter or mesh widgets retain deferred comm-opening effects that serialize invalid color arrays during a later reactive flush and hang the process.
1 open issue
What changed in this PR
This PR adds ipyvolume color validation to shinywidgets’ coercion path, aiming to replace serializer hangs with actionable errors.
Changes:
- Rejects per-point string color arrays on figure scatters and meshes, including figures returned in containers.
- Adds tests for rejected string arrays and accepted scalar strings and numeric colors.
- Documents the intended fix in the changelog.
| File | Description |
|---|---|
| tests/unit/test_ipyvolume.py | Tests invalid and supported color inputs. |
| shinywidgets/_as_widget.py | Validates ipyvolume color arrays during coercion. |
| CHANGELOG.md | Describes the intended hang prevention and error guidance. |
Review effort: Balanced
| if is_string_array: | ||
| raise TypeError( |
There was a problem hiding this comment.
Confirmed — I reproduced the hang: after the coercion error, the rejected scatter's deferred _open_shiny_comm still runs get_state() at the next reactive flush and infinite-loops in color_to_binary_or_json (nothing closes widgets created during a failed render, since an errored render's context is never invalidated).
Fixed in 6b867aa by sanitizing rather than just raising: _reject_ipyvolume_string_color_arrays now resets every offending trait to None before raising the TypeError, so the pending comm opens serialize harmlessly. I considered closing render-created widgets on render error instead, but that's a new lifecycle invariant across every renderer in service of an ipyvolume edge case — and it still wouldn't cover post-render assignment.
The regression test you asked for is test_flush_after_string_color_rejection_does_not_hang: it runs the full render path, leaves the invalid value in place, and flushes — out-of-process with a hard timeout, since in-process a regression would hang the suite instead of failing. Verified it hangs against the pre-fix code and passes with the fix. The existing rejection tests also dropped their manual color resets and now assert the trait was reset to None.
…wed by a hang The TypeError alone didn't prevent the hang: the rejected marks' comm opens were deferred at construction and still serialize state at the next reactive flush (nothing closes widgets created during a failed render), infinite-looping in ipyvolume's serializer. Reset the offending traits to None before raising, and cover it with an out-of-process flush-after-error regression test (in-process it would hang the suite on regression).

Why
Passing a per-point string color array to an ipyvolume scatter or mesh — e.g.
ipv.scatter(x, y, z, color=['tomato', 'seagreen'])— makes ipyvolume's owncolor_to_binary_or_jsonserializer spin forever ('tomato'[0]' == 't', then't'[0] == 't', ...) the first time the widget's state is serialized. The symptom is much worse than a bad plot: the entire Shiny process hangs — every session, every request — with no error anywhere. Users have no way to connect the freeze to their color argument.With this PR,
@render_ipyvolumeraises an actionableTypeErrorat coercion time instead:What changed
as_widget_ipyvolume()now walks the returned figure'sscatters(traitscolorandcolor_selected) andmeshes(traitcolor) — exactly the traits ipyvolume serializes withcolor_to_binary_or_json— and rejects any non-scalar array with string dtype (<U/bytes) or an object array of strings. The check runs before any state serialization, so the hang point is never reached.color='red', stored by ipyvolume as a 0-d array) and numeric per-point arrays (the(N, 3)/(N, 4)RGB(A) float form used throughout ipyvolume's docs) still pass, and are covered by tests.Verification
ipv.scatter(..., color=['tomato', 'seagreen'])infinite-loops inipyvolume/serialize.py:327(killed via a hard timeout).TypeErrorforScatter.color,Scatter.color_selected, andMesh.colorstring arrays (including throughipv.quickscatter()'sContainer), and that scalar strings and numeric arrays still pass.TypeErrorand the reactive flush completes — no hang (previously the process froze in_open_shiny_comm->get_state()).make check-formatandmake pyrightclean;test_ipyvolume.py,test_as_widget.py,test_render_widget.py, andtest_render_widget_base_lifecycle.pyall pass.