Open emer-bestseller opened 3 weeks ago
It looks like the error originates here,
Would it make sense to suppress this error similar to how it's done in updateComponent
?
What do you think, T4rk1n?
@emer-bestseller I think the parameter suppress_callback_exceptions
is to ignore those errors about ID not found in layout
, like dynamic callbacks, not the A nonexistent object was used in an XXX of a Dash callback.
errors.
By the way, there is a trick to handle this kind of error with ALL
pattern-match:
import dash
from dash import html
from dash.dependencies import Input, Output, ALL
app = dash.Dash(
__name__,
prevent_initial_callbacks=True,
suppress_callback_exceptions=True,
)
app.layout = html.Div(
[
html.Button(id="button", children="Button Exists"),
html.Div(id={"type": "exists", "index": "whatever"}),
]
)
@app.callback(
Output("exists", "children"),
Input("button", "n_clicks"),
Input({"type": "exists", "index": ALL}, "n_clicks"),
)
def on_click(_, __):
return "Hello world"
if __name__ == "__main__":
app.run(debug=True)
Ah, so you're saying that it's in fact intended only to silence errors related to (initial) layout validation? In that case, I guess the code is correct, but that the documentation might need some clarification 👍
Reading through the source code, I also started to think about the "hack" of using an ALL wildcard to circumvent the issue. I guess that could be a workaround. Introducing pattern matching callback does increase code complexity somewhat though (partly in syntax, partly in concept; by adding an ALL wildcard the code suggests that there can be multiple elements while in fact the intent is that there will always be exactly one - or zero, of course), so maybe it would make sense to have (another?) flag to silence the exception mentioned in the issue? (:
I don't see any immediate downside of introducing such a flag / allowing these kind of dynamic layout constructs.
Describe your context
Describe the bug
The
suppress_callback_exceptions
doesn't seem to be working as intended. If I run this MWE,and click the button, I get a console error,
Expected behavior
As per the documentation, if this flag is set, I would expect the callback simply to not fire (and thus no errors to be raised).
https://dash.plotly.com/callback-gotchas
Screenshots