Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Can't put null values in store array? #422

Closed
rmarren1 opened this issue Dec 21, 2018 · 9 comments
Closed

Can't put null values in store array? #422

rmarren1 opened this issue Dec 21, 2018 · 9 comments
Assignees
Labels
dash-type-bug Something isn't working as intended

Comments

@rmarren1
Copy link
Contributor

rmarren1 commented Dec 21, 2018

Not sure what is happening with the Store here (is this a bug or a limitation?)

import numpy as np
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output, State

app = dash.Dash(__name__)

app.layout = html.Div([
    html.Div(id='output'),
    dcc.Store(id='store', data={'hello': np.array([1.1, 1.1, None])})
])

@app.callback(Output('output', 'children'),
              [Input('store', 'data')])
def hello(data):
    print(type(data['hello']))
    print(data['hello'])
    return data['hello']  # same happens if you don't render array, e.g just return 'hello'

app.run_server(
    port=8888,
    dev_tools_serve_dev_bundles=True
)

This app seems to work since the array will be printed correctly in the hello callback, suggesting that everything worked out (np.array was serialized to a JSON array with null instead of np.nan, this made it to the redux store, then the hello callback was triggered and the null value was converted to a None.

But this strange error is thrown, no idea why
image

@T4rk1n T4rk1n self-assigned this Dec 26, 2018
@T4rk1n T4rk1n added dash-type-bug Something isn't working as intended and removed Status: Triage Needed labels Dec 26, 2018
@T4rk1n
Copy link
Contributor

T4rk1n commented Dec 26, 2018

Two different bugs.

@rmarren1
Copy link
Contributor Author

rmarren1 commented Dec 27, 2018

changing the root type in a callback also create an infinite recursive loop.

What does this mean? That if my store is {'data': [1, 2, 3]} and I change it to {'data': 'hello'}, it will break? If that what is meant by changing the root type?

@T4rk1n
Copy link
Contributor

T4rk1n commented Dec 27, 2018

No it shouldn't break, just not update.

@T4rk1n
Copy link
Contributor

T4rk1n commented Dec 27, 2018

{'data': [1, 2, 3]} and I change it to {'data': 'hello'}

That worked when I tried, maybe it was just the null check that was missing. I'll still add a test for that use case.

@T4rk1n
Copy link
Contributor

T4rk1n commented Dec 27, 2018

The tests for the store data types changes will need to assert that changes from a combination of the different types will update the output.

>>> pprint.pprint(list(itertools.combinations(['str', 'number', 'dict', 'list', 'None'], 2)))
[('str', 'number'),
 ('str', 'dict'),
 ('str', 'list'),
 ('str', 'None'),
 ('number', 'dict'),
 ('number', 'list'),
 ('number', 'None'),
 ('dict', 'list'),
 ('dict', 'None'),
 ('list', 'None')]

@alexcjohnson
Copy link
Collaborator

You have to be a bit creative to find breaking cases, but a check that the type hasn't changed will fix them all

v1='abc'
v2={0: 'a', 1: 'b', 2: 'c', length: 3}
v3=['a', 'b', 'c']
dataCheck(v2, v1)
dataCheck(v3, v1)
dataCheck(v2, v3)
dataCheck(v3, v2)

While you're at it, would you mind changing the name dataCheck to something more descriptive? (What are we checking? What do true and false mean?) dataChanged perhaps?

@alexcjohnson
Copy link
Collaborator

Also we're not checking for removing keys from an object!
dataCheck({}, {a: 1})

@T4rk1n
Copy link
Contributor

T4rk1n commented Dec 28, 2018

While you're at it, would you mind changing the name dataCheck to something more descriptive? (What are we checking? What do true and false mean?) dataChanged perhaps?

It's a check to know if the data need refreshing for the modified_timestamp to be updated only when the data has actually changed. The component will receive the same data props over and over when other props updates. It's also used when the component mount for the session/local storage_type to know if there was data in the first place and if it's different from the initial data.

@alexcjohnson
Copy link
Collaborator

Yes, I know what it is, but I didn't find that out from its name or (nonexistent) docstring, I had to read through the code and infer its intent. We can do better than that. What it does is a deep equality check, where a return value true means something changed and false means nothing changed. Hence my suggestion dataChanged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dash-type-bug Something isn't working as intended
Projects
None yet
Development

No branches or pull requests

3 participants