Repository navigation
Fix SolaraViz reset crash on raw Solara components - #3494
Conversation
|
Performance benchmarks:
|
|
@Tejasv-Singh Thanks for this PR. Guardrails are great, but in this case you're handling only |
|
Thanks for the implementation! I went through the PR and the approach of adding early validation in One potential improvement could be to avoid checking specifically for Additionally, it might be useful to add a short note in the error message suggesting the correct wrapper usage (for example Overall the approach looks solid and the added test case is helpful in preventing regressions. |
|
Thank you so much @Sahil-Chhoker and @satharyasin-hub for the thoughtful feedback, that's a really good point. You're right that is a much cleaner and more future-proof approach than specifically blocking I'll update the implementation to validate against Mesa's supported param types ( Will push the updated commits shortly! |
0122d46 to
6318e21
Compare
6318e21 to
9ce952f
Compare
|
Hey @Sahil-Chhoker, I've pushed the updated implementation addressing all the feedback. Here's a summary of what changed: Switched to a pure allowlist approach:
Tests updated:
Would love a re-review when you get a chance, thanks so much! 😄 🙌 |
|
Hey @EwoutH, the PR has been approved by @Sahil-Chhoker, all checks are passing, and there are no conflicts with the base branch. Could you take a look and merge when you get a chance? Also, would it be possible to remove the |
Co-authored-by: Sahil Chhoker <[email protected]>
Co-authored-by: Sahil Chhoker <[email protected]> (cherry picked from commit 06a3e8d)
Summary
Fixes a crash in SolaraViz when raw Solara components are passed in model_params instead of Mesa's wrapper classes. It adds early validation to raise a clear
TypeErrorexplaining how to correctly use the components.Bug / Issue
Fixes #3453
When a raw Solara component (yielding a
reacton.core.ValueElement) is passed in the model_params dictionary without Mesa's wrapper classes (e.g.,solara.SliderInt()instead ofmesa.visualization.Slider), it gets incorrectly treated as a "fixed" dictionary parameter.During the reset process, the do_reset() function passes this raw UI Component object directly to the model's init kwargs. The model constructor expects a primitive type but gets a
ValueElementinstead, resulting in a crash with the error:TypeError: 'ValueElement' object cannot be interpreted as an integer.Implementation
SolaraViz.__init__()(mesa/visualization/solara_viz.py) that iterates over model_params.reacton.core.ValueElement, a clearTypeErroris immediately raised directing the user to use wrappers frommesa.visualizationlikeSlider,Checkbox, etc.Testing
solara.SliderInt()to model_params and asserts that the defensiveTypeErroris raised.Additional Notes
This change creates a better Developer Experience (DX) by "failing fast" and explicitly educating the user, rather than failing deep inside the model instantiation step with a cryptic error.
Do let me know your thoughts.