Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix background callbacks progress not deleted after fetch. #2415

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"