You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thanks for providing such a wonderful package. I had an issue and I have been cracking my head at this long enough to belief this is a bug with dash.no_update not being serializiable. While writing this issue, I found that dash.no_update is not the issue but obfusicates the real error.
Situation: Given a user picked date range, I gather data and display it. However, I want to cover the case when there simply is no data to present.
For this, I aim to not update the already presented data and instead show an alert, notifiying the user of the absence of data.
See this line (context below):
returnno_update, no_update, True, df
df is an AssertionError. Apparently, those are not serializiable by json. However, see error log at bottom, dash reports that dash.no_update seems to be the culprit.
The error below is resolved by parsing df into a string via ´str(df)´
@callback(Output(component_id='figcontainer', component_property='figure'),Output(component_id='table', component_property='data'),Output(component_id="alert", component_property='is_open'),Output(component_id="alert",component_property='children'),Input(component_id='date_picker', component_property='start_date'),Input(component_id='date_picker', component_property='end_date'),)defupdate_graph(start, end):
df=get_bookings_in_interval(start, end)
# if there is no data, keep previous states and use alertiftype(df) isAssertionError:
returnno_update, no_update, True, df#else simply display the information and dont update the alertall_appointments, best_days_with_numbers, cleaning_schedule=create_dfs(df)
fig=create_figure(start, end, all_appointments, cleaning_schedule)
returnfig.to_dict(), best_days_with_numbers.to_dict(orient="records"), no_update, no_update#either returns a df or an AssertionErrordefget_bookings_in_interval(start, end):
df=Nonetry:
data=get(#do something)assertdata.status_code==200 , "Failed to fetch bookings"parsed_data=dict(data.json())
assertlen(parsed_data["bookings"]) >0, "No items in Response")
#do somethingexceptAssertionErrorase:
print(e)
returnereturndata
dash.exceptions.InvalidCallbackReturnValue: The callback for `[<Output `figcontainer.figure`>, <Output `table.data`>, <Output `alert.is_open`>, <Output `alert.children`>]`
returned a value having type `NoUpdate`
which is not JSON serializable.
The value in question is either the only value returned,
or is in the top level of the returned list,
and has string representation
`<dash._callback.NoUpdate object at 0x000002A7FA5ACBE0>`
In general, Dash properties can only be
dash components, strings, dictionaries, numbers, None,
or lists of those.
Expected behavior
As dash.no_update is explicitly mentioned, I expected it to be culprit. I think the error hint should either reflect the possibility of other returned values being the issue or explicitly state the correct one.
Screenshots
The text was updated successfully, but these errors were encountered:
gvwilson
changed the title
[BUG] dash.no_update is not serializable by json is raised if other, not serializiable type is passed as output
dash.no_update is not serializable by json is raised if other, not serializiable type is passed as output
Nov 26, 2024
# Handle the case where there is an AssertionError
if isinstance(df, AssertionError):
return no_update, no_update, True, str(df) # Convert AssertionError to a string
# Otherwise, process the data normally
all_appointments, best_days_with_numbers, cleaning_schedule = create_dfs(df)
fig = create_figure(start, end, all_appointments, cleaning_schedule)
return (
fig.to_dict(),
best_days_with_numbers.to_dict(orient="records"),
no_update,
no_update,
)
def get_bookings_in_interval(start, end):
df = None
try:
data = get(# do something)
assert data.status_code == 200, "Failed to fetch bookings"
parsed_data = dict(data.json())
assert len(parsed_data["bookings"]) > 0, "No items in response"
# Process the data and return
df = process_data(parsed_data) # Replace with actual processing logic
except AssertionError as e:
print(e)
return e # Return AssertionError for handling in the callback
return df
Hi everyone,
thanks for providing such a wonderful package. I had an issue and I have been cracking my head at this long enough to belief this is a bug with
dash.no_update
not being serializiable. While writing this issue, I found thatdash.no_update
is not the issue but obfusicates the real error.Situation: Given a user picked date range, I gather data and display it. However, I want to cover the case when there simply is no data to present.
For this, I aim to not update the already presented data and instead show an alert, notifiying the user of the absence of data.
See this line (context below):
df
is anAssertionError
. Apparently, those are not serializiable byjson
. However, see error log at bottom, dash reports thatdash.no_update
seems to be the culprit.The error below is resolved by parsing df into a string via ´str(df)´
Environment used:
Error Log:
Expected behavior
As
dash.no_update
is explicitly mentioned, I expected it to be culprit. I think the error hint should either reflect the possibility of other returned values being the issue or explicitly state the correct one.Screenshots
The text was updated successfully, but these errors were encountered: