plotly / plotly/dash

Inconsistent behavior with dcc.Store initial values and prevent_initial_call

Open
#2,911 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

dash                      2.16.1             
dash-bootstrap-components 1.6.0            
dash-core-components      2.0.0          
dash-html-components      2.0.0                  
dash-iconify              0.1.2               
dash-mantine-components   0.12.1                 
dash-table                5.0.0                   


description
There appears to be an inconsistency in how dcc.Store components behave with different initial values when using prevent_initial_call=True.

Expected behavior
When using prevent_initial_call=True, callbacks should not be triggered on initial load for any dcc.Store, regardless of initial value.

Actual behavior
A callback with prevent_initial_call=True is triggered for a dcc.Store initialized with None, but not for one initialized with an empty dictionary {}.

Minimal reproducible example:

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

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Store(id='store_none', data=None),
    dcc.Store(id='store', data={}),
    html.H3("none store"),
    html.Div(id='output none store', children="Not called yet"),
    html.H3("store"),
    html.Div(id='output store', children="Not called yet"),
])

@app.callback(
    Output('output none store', 'children'),
    Input('store_none', 'data'),
    prevent_initial_call=True
)
def on_store_none(store_none):
    return "called"


@app.callback(
    Output('output store', 'children'),
    Input("store", "data"),
    prevent_initial_call=True
)
def on_store(store):
    return "called"


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

Screenshots

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproducible Dash app in the issue and compare the initial callback behavior for dcc.Store values of None and {} when prevent_initial_call=True. Trace the initial-load callback handling for both values; done means neither callback fires on initial load and the behavior is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.