Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix: validate error message #2508

Merged
merged 3 commits into from
Apr 20, 2023
Merged

Fix: validate error message #2508

merged 3 commits into from
Apr 20, 2023

Conversation

mariusdkm
Copy link
Contributor

This PR fixes the error message, when the wrong number of outputs are present on a callback.

Currently

dash.exceptions.InvalidCallbackReturnValue: Invalid number of output values for {"index":["ALL"],"type":"output"}.children item 0.
Expected 5, got 4
output spec: [{'id': {'index': 0, 'type': 'output'}, 'property': 'children'}, {'id': {'index': 1, 'type': 'output'}, 'property': 'children'}, {'id': {'index': 2, 'type': 'output'}, 'property': 'children'}, {'id': {'index': 3, 'type': 'output'}, 'property': 'children'}]
output value: [['None'], ['None'], ['None'], ['None'], ['None']]

But the Expected 5, got 4 is wrong should be the other way around (Expected 4, got 5)

Example code that throws the error

import dash
from dash import dcc, html, Output, Input, ALL

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        html.Div(
            id={"type": "output", "index": x},
            style={"border": "1px solid black", "width": "100px", "height": "100px"},
        ) for x in range(4)
    ] +
    [
        html.Div(dcc.Input(id="input", type="number"))
    ]
)


@app.callback(
    Output({"type": "output", "index": ALL}, "children"),
    Input("input", "value")
)
def display_output(value):
    return [[str(value)]] * 5


if __name__ == "__main__":
    app.run_server(debug=True)

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

@mariusdkm mariusdkm requested a review from alexcjohnson as a code owner April 16, 2023 16:13
Copy link
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, can you add a changelog entry? Thanks.

dash/_validate.py Outdated Show resolved Hide resolved
@mariusdkm
Copy link
Contributor Author

I renamed the variables in the whole function to be more specific and uniform.

@mariusdkm mariusdkm requested a review from T4rk1n April 20, 2023 15:39
Copy link
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 thanks for cleaning the variables names!

@T4rk1n T4rk1n merged commit 02e16e0 into plotly:dev Apr 20, 2023
@mariusdkm mariusdkm deleted the patch-1 branch April 20, 2023 19:16
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants