Skip to content

Commit

Permalink
Merge pull request #2415 from plotly/fix-2408
Browse files Browse the repository at this point in the history
Fix background callbacks progress not deleted after fetch.
  • Loading branch information
T4rk1n authored Feb 15, 2023
2 parents 9b6f35d + 281dff8 commit ae71e86
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- [#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).
- [#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.

## [UNRELEASED]

## Fixed

- [#2415](https://github.com/plotly/dash/pull/2415) Fix background callbacks progress not deleted after fetch.

## [2.8.1] - 2023-01-30

## Fixed
Expand Down
1 change: 1 addition & 0 deletions dash/long_callback/managers/celery_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def get_progress(self, key):
progress_key = self._make_progress_key(key)
progress_data = self.handle.backend.get(progress_key)
if progress_data:
self.handle.backend.delete(progress_key)
return json.loads(progress_data)

return None
Expand Down
6 changes: 5 additions & 1 deletion dash/long_callback/managers/diskcache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ def call_job_fn(self, key, job_fn, args, context):

def get_progress(self, key):
progress_key = self._make_progress_key(key)
return self.handle.get(progress_key)
progress_data = self.handle.get(progress_key)
if progress_data:
self.handle.delete(progress_key)

return progress_data

def result_ready(self, key):
return self.handle.get(key) is not None
Expand Down
45 changes: 45 additions & 0 deletions tests/integration/long_callback/app_progress_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from dash import Dash, Input, Output, State, html, clientside_callback
import time

from tests.integration.long_callback.utils import get_long_callback_manager

long_callback_manager = get_long_callback_manager()
handle = long_callback_manager.handle

app = Dash(__name__, long_callback_manager=long_callback_manager)

app.layout = html.Div(
[
html.Button("Start", id="start"),
html.Div(id="output"),
html.Div(id="progress-output"),
html.Div(0, id="progress-counter"),
]
)

clientside_callback(
"function(_, previous) { return parseInt(previous) + 1;}",
Output("progress-counter", "children"),
Input("progress-output", "children"),
State("progress-counter", "children"),
prevent_initial_call=True,
)


@app.callback(
Output("output", "children"),
Input("start", "n_clicks"),
progress=Output("progress-output", "children"),
interval=200,
background=True,
prevent_initial_call=True,
)
def on_bg_progress(set_progress, _):
set_progress("start")
time.sleep(2)
set_progress("stop")
return "done"


if __name__ == "__main__":
app.run_server(debug=True)
9 changes: 9 additions & 0 deletions tests/integration/long_callback/test_basic_long_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,12 @@ def test_lcbc013_unordered_state_input(dash_duo, manager):
dash_duo.find_element("#click").click()

dash_duo.wait_for_text_to_equal("#output", "stored")


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.find_element("#start").click()
dash_duo.wait_for_text_to_equal("#output", "done")

assert dash_duo.find_element("#progress-counter").text == "2"

0 comments on commit ae71e86

Please sign in to comment.