Updating dropdown options triggers another callback that not supposed to trigger

I have two callbacks in my app, one updates a dropdown’s options every 5 seconds, and the other callback should be fired when I select something in the dropdown but the first callback not only updates options but also triggers the other callback.

@app.callback(
  Output({"type": "product-filter", "uuid": ALL}, "options"),
  Input("refresh-dropdown-options", "n_intervals")
)
def refresh_product_options(interval):
  # get options from database
  return options

@app.callback(
  Output({"type": "graph-data-storage", "uuid": MATCH}, "data"),
  Input({"type": "product-filter", "uuid": MATCH}, "value"),
  prevent_initial_call=True
)
def get_product_SKUs(value):
  print(value)
  return None

I know a callback can trigger another callback when one’s output is the other’s input but in my case, it’s not. Why ‘refresh_product_options’ triggers ‘get_product_SKUs’?

Hi @Itsimple welcome to the forums.

That is strange. It’s even more strange because we had a similar topic not long ago:

I’ll flag this post, maybe it’s a bug in a recent version update?

I tried installing an old dash version to see if that’s the case and yes it’s a bug, but it seems this bug stayed here for a while. This behavior does happen after dash version 2.8.0. When I installed 2.7.1 it worked as expected.

Edit: Sorry my bad, Same bug happens in 2.7.1 too. The callback didn’t trigger for another reason in 2.7.1 in my code. It’s a bug about pattern matching.

1 Like

Perfect, thanks for the information. This will help the plotly guys.

I added the bug-reporter tag to your topic.

EDIT: I actually can’t reproduce this, one might try it with pattern matching:

import dash
from dash import dcc, html, Input, Output
import random

app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Dropdown(id='d1', options=[1, 2, 3]),
    dcc.Dropdown(id='d2', options=[]),
    html.Pre(id='out', style={'margin-top': '100px'})
])


@app.callback(
    Output('d2', 'options'),
    Input('d1', 'value'),
    prevent_initial_call=True
)
def update(val):
    return {
        1: ['a', 'b'],
        2: ['A', 'B'],
        3: ['x', 'y'],
    }[val]


@app.callback(
    Output('out', 'children'),
    Input('d2', 'value'),
    prevent_initial_call=True
)
def update(_):
    return f'got_triggered_{random.randint(1, 10000)}'


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

Yes, I tried the same code with pattern matching and reproduced it.

import dash
from dash import dcc, html, Input, Output, MATCH, ALL
import random

app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Dropdown(id="d1", options=[1, 2, 3]),
    dcc.Dropdown(id={'type': 'd2', "id": 1}, options=[]),
    dcc.Dropdown(id={'type': 'd2', "id": 2}, options=[]),
    html.Pre(id={"type": 'out', "id": 1}, style={'margin-top': '100px'}),
    html.Pre(id={"type": 'out', "id": 2}, style={'margin-top': '100px'})
])


@app.callback(
    Output({"type": 'd2', "id": ALL}, 'options'),
    Input('d1', 'value'),
    prevent_initial_call=True
)
def update_options(val):
    return [{
        1: ['a', 'b'],
        2: ['A', 'B'],
        3: ['x', 'y'],
    }[val] for _ in range(2)]


@app.callback(
    Output({"type": 'out', "id": MATCH}, 'children'),
    Input({"type": 'd2', "id": MATCH}, 'value'),
    prevent_initial_call=True
)
def update(_):
    return f'got_triggered_{random.randint(1, 10000)}'


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

hi @Itsimple
:wave: welcome to the community.

Thank you for reporting this bug. Can you please open an issue detailing this bug. Being on the Dash repo will help us keep track of it and fix it as soon as possible.

Thank you,

Has a bug report been created? I have the same issue and was told by @AnnMarieW that it was going to be fixed in 2.9.3, but I don’t see any link to this in github.

hi @jokin
Are you referring to this bug?

This one? Fix side effect on updating possible array children triggering callbacks that were not updated. by T4rk1n · Pull Request #2429 · plotly/dash · GitHub

Yes, it still shows up as of 2.9.3. I believe I saw duplicate reports for this so didn’t want to add one more.

hi @jokin
We are aware of this bug. Not all cases related to this bug have been fixed, but we are working on it. Ideally, we’ll be able to fix it fully soon.

2 Likes

hi @Itsimple hi @jokin

I believe the latest release of Dash v2.10.2, tackles this reported bug.

1 Like

Hi @adamschroeder , I confirm, it’s fixed now, thanks a bunch!

1 Like