dcc.Store is asking for a tuple or a list to store data

I am getting the following error when trying to store a dictionary in dcc.Store. Doesn’t it take a dict to store data?

dash._grouping.SchemaTypeValidationError: Schema: [<Output `user_status_check.data`>]
Path: ()
Expected type: (<class 'tuple'>, <class 'list'>)
Received value of type <class 'dict'>:
    {'user_status': [{'status': 'update', 'user_id': None, 'screen_name': 'mfa_russia'}]}

here’s the layout

layout = html.Div([
    tw_user_navbar,
    popup_row,
    dcc.Store(id='user_data_values'),
    dcc.Store(id='user_status_check', storage_type='session', clear_data =True),
    dbc.Row(id='top_row', style={'margin-top': '15px', 'margin-left': '10px'}, justify='left'),
    dbc.Row([
        html.Div(id='left_panel',
                 className='',
                 style={
                     'width': '31%',

                 }
                 ),
        html.Div([html.Div(html.H2(''))], style={'width': '67%'})
    ], id='second_row', style={'margin-top': '15px', 'padding': '0px'}, justify='left'),
    html.Div(
        #
        style={'margin-top': '50px'},
        id='main_lottie'
    )

], style={'padding': '0px',
          'margin-top': '-25px',
          'margin-left': '4rem'})

and the callback, not sure how helpful it would be in answering the question

@app.callback(
    [
    Output('user_status_check', 'data')
    ],
    [
        Input('screen_name', 'value'),
        Input('user_id', 'value'),
    ]
    )
def check_user_status(input_screen_name, input_user_id):
    if input_screen_name or input_user_id:
    # check if the user exists in the db
        from tw_mod.load.pg_db_functions import db_user_check
        user_in_db = db_user_check(screen_name=input_screen_name, user_id=input_user_id)
        # if so check if the user information is up-to-date
        if user_in_db:
            from tw_mod.tw_procssing import check_account_status
            account_status = check_account_status(user_id=input_user_id, screen_name=input_screen_name)
            if account_status:
                return {'user_status':[{'status':'no_update','user_id':input_user_id, 'screen_name':input_screen_name}]}
            else:
                return {'user_status':[{'status':'update','user_id':input_user_id, 'screen_name':input_screen_name}]}
        # if not check if the user is available
        else:
            from tw_mod.extract.tw_functions import get_tw_user
            from tw_mod.tw_procssing import tw_update_user
            api_user = get_tw_user(screen_name=input_screen_name, user_id=input_user_id)
            if 'error_text' in api_user.columns:
                return {'user_status':[{'status':'no_user','user_id':input_user_id, 'screen_name':input_screen_name}]}
            else:
                return {'user_status':[{'status':'user_exists','user_id':input_user_id, 'screen_name':input_screen_name}]}

    else:
        from dash.exceptions import PreventUpdate
        raise PreventUpdate

Hi @vnavdulov

Including the code for the callback was very helpful. You got the error message because the Output as defined under the callback decorator was a list, but the return value was not a list or a tuple.

It’s not necessary to put the Outputs or the Inputs in a list, so you could write the callback like this:


@app.callback(
    Output("user_status_check", "data"),
    Input("screen_name", "value"),
    Input("user_id", "value"),
)
1 Like

:man_facepalming: of course… thank you! I spent an hour fiddling with datatypes and re-reading examples

1 Like