Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing defining potentially non existent components in the running keyword #2898

Merged
merged 6 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- [#2881](https://github.com/plotly/dash/pull/2881) Add outputs_list to window.dash_clientside.callback_context. Fixes [#2877](https://github.com/plotly/dash/issues/2877).

## Fixed

- [#2898](https://github.com/plotly/dash/pull/2898) Fix error thrown when using non-existent components in callback running keyword. Fixes [#2897](https://github.com/plotly/dash/issues/2897).

## [2.17.1] - 2024-06-12

## Fixed
Expand Down
5 changes: 5 additions & 0 deletions dash/dash-renderer/src/actions/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ function updateComponent(component_id: any, props: any) {
return function (dispatch: any, getState: any) {
const paths = getState().paths;
const componentPath = getPath(paths, component_id);
if (typeof componentPath === 'undefined') {
// Can't find the component that was defined in the running keyword,
// Let's skip the component to prevent the dashboard from crashing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to throw an error unless config.suppress_callback_exceptions=True. It is in state.config, could refactor line 335 to const {paths,config} = getState();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a check for that and threw an error when suppress_callback_exceptions=False

return;
}
dispatch(
updateProps({
props,
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/callbacks/test_basic_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,38 @@ def on_click(_):

dash_duo.wait_for_text_to_equal("#output", "done")
dash_duo.wait_for_text_to_equal("#running", "off")


def test_cbsc020_callback_running_non_existing_component(dash_duo):
lock = Lock()
app = Dash(__name__)

app.layout = html.Div(
[
html.Button("start", id="start"),
html.Div(id="output"),
]
)

@app.callback(
Output("output", "children"),
Input("start", "n_clicks"),
running=[
[
Output("non_existent_component", "children"),
html.B("on", id="content"),
"off",
]
],
prevent_initial_call=True,
)
def on_click(_):
with lock:
pass
return "done"

dash_duo.start_server(app)
with lock:
dash_duo.find_element("#start").click()

dash_duo.wait_for_text_to_equal("#output", "done")