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

Intercept KeyError on navigation straight to the metadata tab without adding a config. #95

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
21 changes: 20 additions & 1 deletion wazp/callbacks/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import io
import pathlib as pl
import re
import warnings

import dash
import dash_bootstrap_components as dbc
Expand Down Expand Up @@ -219,7 +220,7 @@ def get_callbacks(app: dash.Dash) -> None:
)
def create_metadata_table_and_buttons(
metadata_output_children: list, app_storage: dict
) -> html.Div:
) -> html.Div | None:
"""Generate html component with a table holding the
metadata per video and with auxiliary buttons for
common table manipulations.
Expand All @@ -241,8 +242,25 @@ def create_metadata_table_and_buttons(
html.Div
html component holding the metadata dash_table and
the auxiliary buttons for common table manipulations

Warns
-----
UserWarning
If no configuration is found (from navigating directly
to the ROI tab, for example).
"""

try:
app_storage["config"]
except KeyError:
# we've likely navigated to the metadata page without an input
# config yaml file... not necessarily an error
warnings.warn("Configuration not yet loaded.")
return html.Div(
children="No configuration loaded. Please add a "
"configuration file from the 'Home' page."
)

if not metadata_output_children:
metadata_table = create_metadata_table_component_from_df(
utils.df_from_metadata_yaml_files(
Expand Down Expand Up @@ -373,6 +391,7 @@ def create_metadata_table_and_buttons(
generate_yaml_tooltip,
]
)
return None
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if we ever get into this situation? Should I throw an error? Or return an empty Div?


@app.callback(
Output("metadata-table", "data"),
Expand Down