You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When a background callback resets one of its own outputs, you cannot set the value of that output back to the previous value, because the basis for the cache key would be the same, and the cached result would be returned. This is an edge case, but it happens frequently enough to warrant a change.
Expected behavior
A callback invoked with the same input values, but different triggered inputs should not retrieve the cached result.
minimal example:
Select "World", and wait for the callback to finish. Press "clear page", and wait for the callback to finish. If you now try to select "World", you cannot do so.
import dash
from dash import html, dcc, Input, Output, no_update
import diskcache
from dash import DiskcacheManager
from uuid import uuid4
import time
launch_uid = uuid4()
cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(
cache, cache_by=[lambda: launch_uid], expire=60
)
app = dash.Dash(__name__, background_callback_manager=background_callback_manager)
app.layout = html.Div(
[
dcc.RadioItems(["Hello", "World"], id="input", value="Hello"),
html.Div(id="output", children="Hello is selected"),
html.Button("clear page", id="button"),
]
)
@app.callback(
Output("output", "children"),
Output("input", "value"),
Input("input", "value"),
Input("button", "n_clicks"),
prevent_initial_call=True,
background=True
)
def update_output(value, n_clicks):
triggered_id = dash.callback_context.triggered_id
print(triggered_id)
time.sleep(5)
match triggered_id:
case "input":
return value + " is selected", no_update
case "button":
return "Hello is selected", "Hello"
case _:
return no_update, no_update
if __name__ == "__main__":
app.run_server()
The text was updated successfully, but these errors were encountered:
Describe the bug
When a background callback resets one of its own outputs, you cannot set the value of that output back to the previous value, because the basis for the cache key would be the same, and the cached result would be returned. This is an edge case, but it happens frequently enough to warrant a change.
Expected behavior
A callback invoked with the same input values, but different triggered inputs should not retrieve the cached result.
minimal example:
Select "World", and wait for the callback to finish. Press "clear page", and wait for the callback to finish. If you now try to select "World", you cannot do so.
The text was updated successfully, but these errors were encountered: