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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]

## Fixed

- [#2508](https://github.com/plotly/dash/pull/2508) Fix error message, when callback output has different length than spec

## [2.9.3] - 2023-04-13

## Fixed
Expand Down
30 changes: 15 additions & 15 deletions dash/_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,49 +161,49 @@ def validate_and_group_input_args(flat_args, arg_index_grouping):
return func_args, func_kwargs


def validate_multi_return(outputs_list, output_value, callback_id):
if not isinstance(output_value, (list, tuple)):
def validate_multi_return(output_lists, output_values, callback_id):
if not isinstance(output_values, (list, tuple)):
raise exceptions.InvalidCallbackReturnValue(
dedent(
f"""
The callback {callback_id} is a multi-output.
Expected the output type to be a list or tuple but got:
{output_value!r}.
{output_values!r}.
"""
)
)

if len(output_value) != len(outputs_list):
if len(output_values) != len(output_lists):
raise exceptions.InvalidCallbackReturnValue(
f"""
Invalid number of output values for {callback_id}.
Expected {len(outputs_list)}, got {len(output_value)}
Expected {len(output_lists)}, got {len(output_values)}
"""
)

for i, outi in enumerate(outputs_list):
if isinstance(outi, list):
vi = output_value[i]
if not isinstance(vi, (list, tuple)):
for i, output_spec in enumerate(output_lists):
if isinstance(output_spec, list):
output_value = output_values[i]
if not isinstance(output_value, (list, tuple)):
raise exceptions.InvalidCallbackReturnValue(
dedent(
f"""
The callback {callback_id} output {i} is a wildcard multi-output.
Expected the output type to be a list or tuple but got:
{vi!r}.
output spec: {outi!r}
{output_value!r}.
output spec: {output_spec!r}
"""
)
)

if len(vi) != len(outi):
if len(output_value) != len(output_spec):
raise exceptions.InvalidCallbackReturnValue(
dedent(
f"""
Invalid number of output values for {callback_id} item {i}.
Expected {len(vi)}, got {len(outi)}
output spec: {outi!r}
output value: {vi!r}
Expected {len(output_spec)}, got {len(output_value)}
output spec: {output_spec!r}
output value: {output_value!r}
"""
)
)
Expand Down