emilhe / dash-extensions

The dash-extensions package is a collection of utility functions, syntax extensions, and Dash components that aim to improve the Dash development experience
https://www.dash-extensions.com/
MIT License
417 stars 59 forks source link

`Operator().dict.update` produces erroneous messages in browser console #245

Closed plutonium-94 closed 1 year ago

plutonium-94 commented 1 year ago

Here is a demo application:

# -*- coding: utf-8 -*-
from dash import html, dcc, Output, Input, State
from dash.exceptions import PreventUpdate
from dash_extensions.enrich import DashProxy, OperatorTransform, OperatorOutput, Operator

app = DashProxy(__name__, transforms=[OperatorTransform()])

app.layout = html.Div([
    dcc.Store(id='store', data={}),
    html.Div(id='output'),
    html.Button('update', id='button'),
])

@app.callback(OperatorOutput('store', 'data'), Input('button', 'n_clicks'), State('store', 'data'))
def update_store(n_clicks, data):
    if not data and n_clicks:
        return Operator().dict.update({'a': 1})
    raise PreventUpdate

@app.callback(Output('output', 'children'), Input('store', 'data'))
def update_output(data):
    return str(data)

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

When the update button was clicked, the data in store was actually updated, so the following messages in browser console were erroneous:

Received unknown action for component store_data.
{opr: 'dict_update', pth: Array(0), obj: {…}}
Update will be skipped.

Add a break; above https://github.com/thedirtyfew/dash-extensions/blob/2d03763b42b82fc827f50d0527d236a04a819921/dash_extensions/enrich.py#L1558 may solve the issue.

emilhe commented 1 year ago

Ah yes, that's obviously a bug. Thanks for the correction :)