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

set_props only updating last output in background callbacks #3104

Open
faulty13 opened this issue Dec 11, 2024 · 3 comments · May be fixed by #3182
Open

set_props only updating last output in background callbacks #3104

faulty13 opened this issue Dec 11, 2024 · 3 comments · May be fixed by #3182
Labels
bug something broken P3 backlog

Comments

@faulty13
Copy link

faulty13 commented Dec 11, 2024

Describe your context
Mac OS, occurring in Safari & Chrome

dash                 2.18.2
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table           5.0.0

Describe the bug

When updating two different components via set_props, in a background callback with running, only the last output is updated. No console errors encountered.

Further testing:

  • If I remove the background, and running, then both outputs are updated as expected.
  • The issue persists if I replace running with cancel.
  • If I swap the order of the set_props lines, the other component updates instead.

See reproducible example below:

from dash import Dash, Output, Input, html, set_props, DiskcacheManager
import diskcache
import dash

cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(cache)

app = Dash()

app.layout = [
    html.Button("start", id="start"),
    html.Div("initial", id="output"),
    html.Div("initial 2", id="output-2"),
]

@app.callback(
    Input("start", "n_clicks"),
    background=True,
    running=[
        (Output("start", "disabled"), True, False)
    ],
    manager=background_callback_manager,
)
def on_click(_):
    set_props("output", {"children": "changed"})
    set_props("output-2", {"style": {"background": "red"}})

if __name__ == "__main__":
    app.run(debug=True)

Expected behavior

All outputs should update, not just the last one.
Image

@gvwilson gvwilson added bug something broken P3 backlog labels Dec 12, 2024
@gvwilson gvwilson changed the title [BUG] set_props only updating last output in background callbacks set_props only updating last output in background callbacks Dec 12, 2024
@T4rk1n
Copy link
Contributor

T4rk1n commented Jan 6, 2025

This is bug with the Diskcache manager, it only set the last value here:

def _set_props(_id, props):
cache.set(f"{result_key}-set_props", {_id: props})

This need to be check if there is an old value first.

@olgavoz1971
Copy link

I have the same problem with set_props in the background callback with Redis+Celery

@Raahul-Singh Raahul-Singh linked a pull request Feb 21, 2025 that will close this issue
8 tasks
@Raahul-Singh
Copy link

Raahul-Singh commented Feb 21, 2025

Hi, I've opened an MR (#3182) fixing this. Thanks a ton @T4rk1n for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants