Skip to content

Commit 3b63a81

Browse files
author
Eric Smyth
committed
Fix to prevent update of sidebar store if the parameters are the same.
Fix to hash deserialization of Number with value of `None` which `urlencode` serializes as the string "None"
1 parent 44de731 commit 3b63a81

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/chime_dash/app/services/callbacks.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from collections import OrderedDict
44
from urllib.parse import parse_qsl, urlencode
55
from dash.exceptions import PreventUpdate
6-
from dateutil.parser import parse as parse_date
76

87
from chime_dash.app.utils.callbacks import ChimeCallback, register_callbacks
98
from chime_dash.app.utils import (
@@ -147,6 +146,11 @@ def update_parameters(i, *input_values) -> List[dict]:
147146

148147
def __init__(self, component_instance):
149148
def update_parameters_helper(*args, **kwargs):
149+
input_values = list(args)
150+
input_dict = dict(zip(component_instance.input_value_map.keys(), input_values))
151+
sidebar_data = input_values.pop(-1)
152+
if sidebar_data and input_dict and input_dict == sidebar_data["inputs_dict"]:
153+
raise PreventUpdate
150154
return SidebarCallbacks.update_parameters(component_instance, *args)
151155

152156
super().__init__(
@@ -156,6 +160,7 @@ def update_parameters_helper(*args, **kwargs):
156160
changed_elements=component_instance.input_value_map,
157161
dom_updates={"sidebar-store": "data"},
158162
callback_fn=update_parameters_helper,
163+
stores=["sidebar-store"],
159164
)
160165
]
161166
)
@@ -165,13 +170,17 @@ def update_parameters_helper(*args, **kwargs):
165170
class RootCallbacks(ComponentCallbacks):
166171
@staticmethod
167172
def try_parsing_number(v):
168-
try:
169-
return int(v)
170-
except ValueError:
173+
if v == 'None':
174+
result = None
175+
else:
171176
try:
172-
return float(v)
177+
result = int(v)
173178
except ValueError:
174-
return v
179+
try:
180+
result = float(v)
181+
except ValueError:
182+
result = v
183+
return result
175184

176185
@staticmethod
177186
def get_inputs(val_dict, inputs_keys):
@@ -185,8 +194,6 @@ def parse_hash(hash_str, sidebar_input_types):
185194
value_type = sidebar_input_types[key]
186195
if value_type == "number":
187196
parsed_value = RootCallbacks.try_parsing_number(value)
188-
# elif value_type == "date":
189-
# parsed_value = parse_date(value)
190197
else:
191198
parsed_value = value
192199
hash_dict[key] = parsed_value
@@ -208,10 +215,12 @@ def hash_changed(sidebar_input_types, hash_str=None, root_data=None):
208215
def stores_changed(inputs_keys, root_mod, sidebar_mod, root_data, sidebar_data):
209216
root_modified = root_mod or 0
210217
sidebar_modified = sidebar_mod or 0
211-
if root_modified < sidebar_modified:
218+
if root_data and sidebar_data and root_data == sidebar_data.get("inputs_dict", None):
219+
raise PreventUpdate
220+
if (root_modified + 100) < sidebar_modified:
212221
inputs_dict = sidebar_data["inputs_dict"]
213222
new_val = RootCallbacks.get_inputs(inputs_dict, inputs_keys)
214-
elif root_modified > sidebar_modified:
223+
elif root_modified > (sidebar_modified + 100):
215224
new_val = RootCallbacks.get_inputs(root_data, inputs_keys)
216225
else:
217226
raise PreventUpdate

src/chime_dash/app/utils/callbacks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def wrap(self, app: Dash):
3737
@lru_cache(maxsize=32)
3838
@app.callback(self.outputs, self.inputs, self.stores)
3939
def callback_wrapper(*args, **kwargs):
40+
print(str(self.callback_fn))
4041
return self.callback_fn(*args, **kwargs)
4142
else:
4243
@app.callback(self.outputs, self.inputs, self.stores)

0 commit comments

Comments
 (0)