Skip to content

[BUG] when an unserializable object is nested within a valid object, PlotlyJSONEncoder throws misleading exceptions #1808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JonThom opened this issue Oct 20, 2021 · 1 comment

Comments

@JonThom
Copy link

JonThom commented Oct 20, 2021

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)
@JonThom
Copy link
Author

JonThom commented Oct 20, 2021

@alexcjohnson as described in comment to #1014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant