[BUG] when an unserializable object is nested within a valid object, PlotlyJSONEncoder throws misleading exceptions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 24.4k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 13
Description
Describe your context
dash 2.0.0
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table 5.0.0
Describe the bug
When a non json-serializable object is nested within a valid object, PlotlyJSONEncoder throws misleading exceptions.
Expected behavior
PlotlyJSONEncoder should throw an exception stating that the offending object is non-serializable.
Reproducible example
The following example reproduces two different misleading exceptions.
(NB: we allow Dash to call the callbacks and trigger the exceptions on initial render)
import dash
from dash import html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.Button("output to 1", id="buttonA"),
html.Button("output to 2 and 3", id="buttonB"),
html.Div(id="output1"),
html.Div(id="output2"),
html.Div(id="output3")
]
)
@app.callback(
[Output("output1", "children")],
Input("buttonA", "n_clicks")
)
def non_serializable_output_in_list(n_clicks):
# nested not jsonifiable output inside a list
out1 = {
"nested_not_jsonifiable":{"a":1, "b":2}.values()
}
return [out1]
@app.callback(
[
Output("output2", "children"),
Output("output3", "children")
],
Input("buttonB", "n_clicks")
)
def non_serializable_output_alongside_no_update(n_clicks):
# nested non-jsonifiable object alongside a dash.no_update
out2 = {
"nested_not_jsonifiable":{"a":1, "b":2}.values()
}
out3 = dash.no_update
return [out2, out3]
if __name__ == '__main__':
app.run_server(debug=True)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with PlotlyJSONEncoder and run the reproducible Dash callback examples from the issue, focusing on the nested values-view object and the dash.no_update case. Done means both cases raise an exception that identifies the offending non-serializable object instead of a misleading exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100