From 3e42726586956d27b2bbd38aa76769929a7b3eb5 Mon Sep 17 00:00:00 2001 From: leeagustin Date: Sun, 23 Jun 2024 20:31:43 -0700 Subject: [PATCH 1/5] Allows for no_update in background callback set_progress --- dash/_callback.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dash/_callback.py b/dash/_callback.py index 8ebc274213..e45e57c19a 100644 --- a/dash/_callback.py +++ b/dash/_callback.py @@ -426,7 +426,9 @@ def add_context(*args, **kwargs): progress = callback_manager.get_progress(cache_key) if progress: response["progress"] = { - str(x): progress[i] for i, x in enumerate(progress_outputs) + str(x): progress[i] + for i, x in enumerate(progress_outputs) + if not isinstance(progress[i], NoUpdate) } output_value = callback_manager.get_result(cache_key, job_id) From 81f648a6c497cae655ce1fb0d684308fa2880265 Mon Sep 17 00:00:00 2001 From: leeagustin Date: Sun, 23 Jun 2024 20:32:30 -0700 Subject: [PATCH 2/5] Modifies integration test to set_progress to no_update --- tests/integration/long_callback/app_progress_delete.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/integration/long_callback/app_progress_delete.py b/tests/integration/long_callback/app_progress_delete.py index 2fdf08af61..e82e344d8c 100644 --- a/tests/integration/long_callback/app_progress_delete.py +++ b/tests/integration/long_callback/app_progress_delete.py @@ -1,4 +1,4 @@ -from dash import Dash, Input, Output, State, html, clientside_callback +from dash import Dash, Input, Output, State, html, clientside_callback, no_update import time from tests.integration.long_callback.utils import get_long_callback_manager @@ -36,7 +36,9 @@ ) def on_bg_progress(set_progress, _): set_progress("start") - time.sleep(2) + time.sleep(1) + set_progress(no_update) + time.sleep(1) set_progress("stop") return "done" From 7437e2b2ba01632a9a381175f88ff4da654ddf09 Mon Sep 17 00:00:00 2001 From: leeagustin Date: Tue, 25 Jun 2024 18:40:27 -0700 Subject: [PATCH 3/5] Modifies test to ensure using set_progress(no_update) does not reset progress --- .../integration/long_callback/app_progress_delete.py | 7 ++++--- .../long_callback/test_basic_long_callback014.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/integration/long_callback/app_progress_delete.py b/tests/integration/long_callback/app_progress_delete.py index e82e344d8c..cb6338cb5b 100644 --- a/tests/integration/long_callback/app_progress_delete.py +++ b/tests/integration/long_callback/app_progress_delete.py @@ -36,12 +36,13 @@ ) def on_bg_progress(set_progress, _): set_progress("start") - time.sleep(1) - set_progress(no_update) - time.sleep(1) + time.sleep(2) set_progress("stop") + time.sleep(2) + set_progress(no_update) return "done" if __name__ == "__main__": app.run_server(debug=True) +application = app.server diff --git a/tests/integration/long_callback/test_basic_long_callback014.py b/tests/integration/long_callback/test_basic_long_callback014.py index 47ff2f1155..b3ded197d8 100644 --- a/tests/integration/long_callback/test_basic_long_callback014.py +++ b/tests/integration/long_callback/test_basic_long_callback014.py @@ -11,7 +11,17 @@ def test_lcbc014_progress_delete(dash_duo, manager): with setup_long_callback_app(manager, "app_progress_delete") as app: dash_duo.start_server(app) + + dash_duo.wait_for_text_to_equal("#progress-output", "") + assert dash_duo.find_element("#progress-counter").text == "0" + dash_duo.find_element("#start").click() - dash_duo.wait_for_text_to_equal("#output", "done") + dash_duo.wait_for_text_to_equal("#progress-output", "start") + assert dash_duo.find_element("#progress-counter").text == "1" + + dash_duo.wait_for_text_to_equal("#progress-output", "stop") + assert dash_duo.find_element("#progress-counter").text == "2" + + dash_duo.wait_for_text_to_equal("#output", "done") assert dash_duo.find_element("#progress-counter").text == "2" From dbfcdb1073a0c81c2cf825ae944896ced456df2d Mon Sep 17 00:00:00 2001 From: leeagustin Date: Tue, 25 Jun 2024 18:50:33 -0700 Subject: [PATCH 4/5] Removes unnecessary line used for debugging --- tests/integration/long_callback/app_progress_delete.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/long_callback/app_progress_delete.py b/tests/integration/long_callback/app_progress_delete.py index cb6338cb5b..8f9f9e1a13 100644 --- a/tests/integration/long_callback/app_progress_delete.py +++ b/tests/integration/long_callback/app_progress_delete.py @@ -45,4 +45,3 @@ def on_bg_progress(set_progress, _): if __name__ == "__main__": app.run_server(debug=True) -application = app.server From 21bc4b2178e26ef8de287197ac43d685134e5e4a Mon Sep 17 00:00:00 2001 From: leeagustin Date: Thu, 27 Jun 2024 18:24:51 -0700 Subject: [PATCH 5/5] Adds lock to test_basic_long_callback014.py --- .../long_callback/app_progress_delete.py | 12 +++++++----- .../long_callback/test_basic_long_callback014.py | 15 +++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/tests/integration/long_callback/app_progress_delete.py b/tests/integration/long_callback/app_progress_delete.py index 8f9f9e1a13..50926e6091 100644 --- a/tests/integration/long_callback/app_progress_delete.py +++ b/tests/integration/long_callback/app_progress_delete.py @@ -16,6 +16,7 @@ html.Div(0, id="progress-counter"), ] ) +app.test_lock = lock = long_callback_manager.test_lock clientside_callback( "function(_, previous) { return parseInt(previous) + 1;}", @@ -35,11 +36,12 @@ prevent_initial_call=True, ) def on_bg_progress(set_progress, _): - set_progress("start") - time.sleep(2) - set_progress("stop") - time.sleep(2) - set_progress(no_update) + with lock: + set_progress("start") + time.sleep(0.5) + set_progress("stop") + time.sleep(0.5) + set_progress(no_update) return "done" diff --git a/tests/integration/long_callback/test_basic_long_callback014.py b/tests/integration/long_callback/test_basic_long_callback014.py index b3ded197d8..826407f210 100644 --- a/tests/integration/long_callback/test_basic_long_callback014.py +++ b/tests/integration/long_callback/test_basic_long_callback014.py @@ -11,17 +11,8 @@ def test_lcbc014_progress_delete(dash_duo, manager): with setup_long_callback_app(manager, "app_progress_delete") as app: dash_duo.start_server(app) - - dash_duo.wait_for_text_to_equal("#progress-output", "") - assert dash_duo.find_element("#progress-counter").text == "0" - dash_duo.find_element("#start").click() - - dash_duo.wait_for_text_to_equal("#progress-output", "start") - assert dash_duo.find_element("#progress-counter").text == "1" - - dash_duo.wait_for_text_to_equal("#progress-output", "stop") - assert dash_duo.find_element("#progress-counter").text == "2" - dash_duo.wait_for_text_to_equal("#output", "done") - assert dash_duo.find_element("#progress-counter").text == "2" + with app.test_lock: + assert dash_duo.find_element("#progress-output").text == "stop" + assert dash_duo.find_element("#progress-counter").text == "2"