From fc73c165c8c4a36ee63a4831f046637a68e61402 Mon Sep 17 00:00:00 2001 From: philippe Date: Thu, 5 Sep 2024 14:05:17 -0400 Subject: [PATCH 1/4] Fix multioutput requiring same number of no_update. --- dash/_callback.py | 14 +++++--- .../callbacks/test_missing_outputs.py | 35 ++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/dash/_callback.py b/dash/_callback.py index 54a2e5a64c..08314cc63a 100644 --- a/dash/_callback.py +++ b/dash/_callback.py @@ -528,12 +528,16 @@ def add_context(*args, **kwargs): # list or tuple output_value = list(output_value) - # Flatten grouping and validate grouping structure - flat_output_values = flatten_grouping(output_value, output) + if NoUpdate.is_no_update(output_value): + flat_output_values = [output_value] + else: + # Flatten grouping and validate grouping structure + flat_output_values = flatten_grouping(output_value, output) - _validate.validate_multi_return( - output_spec, flat_output_values, callback_id - ) + if not NoUpdate.is_no_update(output_value): + _validate.validate_multi_return( + output_spec, flat_output_values, callback_id + ) for val, spec in zip(flat_output_values, output_spec): if NoUpdate.is_no_update(val): diff --git a/tests/integration/callbacks/test_missing_outputs.py b/tests/integration/callbacks/test_missing_outputs.py index fbebbbc0ce..fa3818c820 100644 --- a/tests/integration/callbacks/test_missing_outputs.py +++ b/tests/integration/callbacks/test_missing_outputs.py @@ -1,8 +1,10 @@ +import time + import pytest from multiprocessing import Lock, Value import dash -from dash import Dash, Input, Output, ALL, MATCH, html, dcc +from dash import Dash, Input, Output, ALL, MATCH, html, dcc, no_update from dash.testing.wait import until @@ -336,3 +338,34 @@ def chapter2_assertions(): dash_duo._wait_for_callbacks() chapter2_assertions() assert not dash_duo.get_logs() + + +def test_cbmo005_no_update_single_to_multi(dash_duo): + # Bugfix for #2986 + app = dash.Dash(__name__) + + app.layout = html.Div( + [ + dcc.Input(id="input-box", type="text", value=""), + html.Button("Submit", id="button"), + html.Div(id="output-1", children="Output 1 will be displayed here"), + html.Div(id="output-2", children="Output 2 will be displayed here"), + ] + ) + + @app.callback( + Output("output-1", "children"), + Output("output-2", "children"), + Input("button", "n_clicks"), + Input("input-box", "value"), + ) + def update_outputs(n_clicks, value): + if n_clicks is None: + return no_update + return "Hello", "world!" + + dash_duo.start_server(app) + + # just wait to make sure the error get logged. + time.sleep(1) + assert dash_duo.get_logs() == [] From 2f16529841e3a347550f70155c0280edf946a8e6 Mon Sep 17 00:00:00 2001 From: philippe Date: Thu, 5 Sep 2024 14:27:56 -0400 Subject: [PATCH 2/4] Set rddp001 as flaky --- tests/integration/renderer/test_dependencies.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration/renderer/test_dependencies.py b/tests/integration/renderer/test_dependencies.py index 07ad2a528d..fc23f6b729 100644 --- a/tests/integration/renderer/test_dependencies.py +++ b/tests/integration/renderer/test_dependencies.py @@ -2,7 +2,10 @@ from dash import Dash, html, dcc, Input, Output +from flaky import flaky + +@flaky(max_runs=3) def test_rddp001_dependencies_on_components_that_dont_exist(dash_duo): app = Dash(__name__, suppress_callback_exceptions=True) app.layout = html.Div( From b942f1aa684d33eeeb3708c2dc5f936071cc355e Mon Sep 17 00:00:00 2001 From: philippe Date: Thu, 5 Sep 2024 14:47:13 -0400 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f96e4ca99..f1bdcead42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [UNRELEASED] +## Fixed + +- [#2987](https://github.com/plotly/dash/pull/2987) Fix multioutput requiring same number of no_update. Fixes [#2986](https://github.com/plotly/dash/issues/2986) + ## Deprecated - [#2985](https://github.com/plotly/dash/pull/2985) Deprecate dynamic component loader. From 2495492dd5e14365c3b0a60367c26321691318f7 Mon Sep 17 00:00:00 2001 From: philippe Date: Thu, 5 Sep 2024 15:09:00 -0400 Subject: [PATCH 4/4] build