Skip to content

Commit a9f757c

Browse files
committed
Add test arbitrary callbacks for background callbacks.
1 parent fb60ce0 commit a9f757c

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

dash/_callback.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ def add_context(*args, **kwargs):
351351
)
352352

353353
response = {"multi": True}
354+
has_update = False
354355

355356
if long is not None:
356357
if not callback_manager:
@@ -455,6 +456,7 @@ def add_context(*args, **kwargs):
455456
updated_props = callback_manager.get_updated_props(cache_key)
456457
if len(updated_props) > 0:
457458
response["sideUpdate"] = updated_props
459+
has_update = True
458460

459461
if output_value is callback_manager.UNDEFINED:
460462
return to_json(response)
@@ -480,7 +482,6 @@ def add_context(*args, **kwargs):
480482
flat_output_values = flatten_grouping(output_value, output)
481483

482484
component_ids = collections.defaultdict(dict)
483-
has_update = False
484485
if not no_output:
485486
_validate.validate_multi_return(
486487
output_spec, flat_output_values, callback_id
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from dash import Dash, Input, Output, html, callback, set_props
2+
import time
3+
4+
from tests.integration.long_callback.utils import get_long_callback_manager
5+
6+
long_callback_manager = get_long_callback_manager()
7+
handle = long_callback_manager.handle
8+
9+
app = Dash(__name__, long_callback_manager=long_callback_manager)
10+
app.test_lock = lock = long_callback_manager.test_lock
11+
12+
app.layout = html.Div(
13+
[
14+
html.Button("start", id="start"),
15+
html.Div(id="secondary"),
16+
html.Div(id="no-output"),
17+
html.Div("initial", id="output"),
18+
html.Button("start-no-output", id="start-no-output"),
19+
]
20+
)
21+
22+
23+
@callback(
24+
Output("output", "children"),
25+
Input("start", "n_clicks"),
26+
prevent_initial_call=True,
27+
background=True,
28+
)
29+
def on_click(_):
30+
set_props("secondary", {"children": "first"})
31+
time.sleep(2)
32+
set_props("secondary", {"children": "second"})
33+
return "completed"
34+
35+
36+
@callback(
37+
Input("start-no-output", "n_clicks"),
38+
prevent_initial_call=True,
39+
background=True,
40+
)
41+
def on_click(_):
42+
set_props("no-output", {"children": "started"})
43+
time.sleep(2)
44+
set_props("no-output", {"children": "completed"})
45+
46+
47+
if __name__ == "__main__":
48+
app.run_server(debug=True)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from tests.integration.long_callback.utils import setup_long_callback_app
2+
3+
4+
def test_lcbc017_long_callback_set_props(dash_duo, manager):
5+
with setup_long_callback_app(manager, "app_arbitrary") as app:
6+
dash_duo.start_server(app)
7+
8+
with app.test_lock:
9+
dash_duo.find_element("#start").click()
10+
11+
dash_duo.wait_for_text_to_equal("#secondary", "first")
12+
dash_duo.wait_for_text_to_equal("#output", "initial")
13+
dash_duo.wait_for_text_to_equal("#secondary", "second")
14+
dash_duo.wait_for_text_to_equal("#output", "completed")
15+
16+
dash_duo.find_element("#start-no-output").click()
17+
18+
dash_duo.wait_for_text_to_equal("#no-output", "started")
19+
dash_duo.wait_for_text_to_equal("#no-output", "completed")

0 commit comments

Comments
 (0)