Skip to content

Commit ae71e86

Browse files
authored
Merge pull request #2415 from plotly/fix-2408
Fix background callbacks progress not deleted after fetch.
2 parents 9b6f35d + 281dff8 commit ae71e86

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1414
- [#2417](https://github.com/plotly/dash/pull/2417) Disable the pytest plugin if `dash[testing]` not installed, fix [#946](https://github.com/plotly/dash/issues/946).
1515
- [#2417](https://github.com/plotly/dash/pull/2417) Do not swallow the original error to get the webdriver, easier to know what is wrong after updating the browser but the driver.
1616

17+
## [UNRELEASED]
18+
19+
## Fixed
20+
21+
- [#2415](https://github.com/plotly/dash/pull/2415) Fix background callbacks progress not deleted after fetch.
22+
1723
## [2.8.1] - 2023-01-30
1824

1925
## Fixed

dash/long_callback/managers/celery_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def get_progress(self, key):
9898
progress_key = self._make_progress_key(key)
9999
progress_data = self.handle.backend.get(progress_key)
100100
if progress_data:
101+
self.handle.backend.delete(progress_key)
101102
return json.loads(progress_data)
102103

103104
return None

dash/long_callback/managers/diskcache_manager.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ def call_job_fn(self, key, job_fn, args, context):
127127

128128
def get_progress(self, key):
129129
progress_key = self._make_progress_key(key)
130-
return self.handle.get(progress_key)
130+
progress_data = self.handle.get(progress_key)
131+
if progress_data:
132+
self.handle.delete(progress_key)
133+
134+
return progress_data
131135

132136
def result_ready(self, key):
133137
return self.handle.get(key) is not None
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from dash import Dash, Input, Output, State, html, clientside_callback
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+
11+
app.layout = html.Div(
12+
[
13+
html.Button("Start", id="start"),
14+
html.Div(id="output"),
15+
html.Div(id="progress-output"),
16+
html.Div(0, id="progress-counter"),
17+
]
18+
)
19+
20+
clientside_callback(
21+
"function(_, previous) { return parseInt(previous) + 1;}",
22+
Output("progress-counter", "children"),
23+
Input("progress-output", "children"),
24+
State("progress-counter", "children"),
25+
prevent_initial_call=True,
26+
)
27+
28+
29+
@app.callback(
30+
Output("output", "children"),
31+
Input("start", "n_clicks"),
32+
progress=Output("progress-output", "children"),
33+
interval=200,
34+
background=True,
35+
prevent_initial_call=True,
36+
)
37+
def on_bg_progress(set_progress, _):
38+
set_progress("start")
39+
time.sleep(2)
40+
set_progress("stop")
41+
return "done"
42+
43+
44+
if __name__ == "__main__":
45+
app.run_server(debug=True)

tests/integration/long_callback/test_basic_long_callback.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,12 @@ def test_lcbc013_unordered_state_input(dash_duo, manager):
538538
dash_duo.find_element("#click").click()
539539

540540
dash_duo.wait_for_text_to_equal("#output", "stored")
541+
542+
543+
def test_lcbc014_progress_delete(dash_duo, manager):
544+
with setup_long_callback_app(manager, "app_progress_delete") as app:
545+
dash_duo.start_server(app)
546+
dash_duo.find_element("#start").click()
547+
dash_duo.wait_for_text_to_equal("#output", "done")
548+
549+
assert dash_duo.find_element("#progress-counter").text == "2"

0 commit comments

Comments
 (0)