Skip to content

Commit 2cf5f1a

Browse files
Felipedinocristian-tamblay
authored andcommitted
fix: Improve error messages for unknown explainers and data loaders
1 parent ebb7eb6 commit 2cf5f1a

4 files changed

Lines changed: 46 additions & 9 deletions

File tree

DashAI/back/units/explanation_artifacts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def build_explainer(scope: str, selected: dict, trained_model: Any) -> Any:
5555
except Exception as e:
5656
log.exception(e)
5757
raise JobError(
58-
f"""Unable to find the {scope} explainer with name
59-
{explainer_name} in registry.""",
58+
f"Unable to find the {scope} explainer with name "
59+
f"{explainer_name} in registry.",
6060
) from e
6161

6262
try:

DashAI/back/units/load_datafile_dataset_unit.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ def execute(self, ctx: ExecutionContext) -> None:
133133

134134
source = _resolve_source_file(work_dir, selected_file)
135135

136+
# Looked up among the readers specifically, not with the registry's
137+
# global ``registry[name]``: that one walks every component type, so a
138+
# metric or a model whose name happened to be passed here would be
139+
# instantiated as if it could read a file instead of being rejected.
136140
dataloader_name = dataloader_config["component"]
137-
registry = component_registry.registry.get("DataLoader", {})
138-
if dataloader_name not in registry:
141+
readers = component_registry.registry.get("DataLoader", {})
142+
if dataloader_name not in readers:
139143
raise JobError(f"DataLoader '{dataloader_name}' not found in registry.")
140-
dataloader = registry[dataloader_name]["class"]()
144+
dataloader = readers[dataloader_name]["class"]()
141145

142146
log.debug("Loading hub dataset from %s using %s", source, dataloader_name)
143147
ctx.put(

tests/back/api/test_explainer_job.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,11 @@ def test_a_model_that_cannot_be_loaded_names_the_path(client, run_id):
503503
def test_an_unknown_explainer_name_is_reported_with_the_multiline_message(
504504
client, run_id
505505
):
506-
"""The message is a triple-quoted f-string, so its newline and indentation
507-
are literally part of the text the user sees. Pinned as-is."""
506+
"""One line, so it stays readable wherever it surfaces.
507+
508+
It used to be a triple-quoted f-string, which put a newline and the source
509+
file's indentation literally inside the text the user reads.
510+
"""
508511
explainer_id = _create_global_explainer(
509512
client, run_id, explainer_name="NoSuchExplainer"
510513
)
@@ -513,8 +516,7 @@ def test_an_unknown_explainer_name_is_reported_with_the_multiline_message(
513516
ExplainerJob(explainer_id=explainer_id, explainer_scope="global").run()
514517

515518
assert str(excinfo.value) == (
516-
"Unable to find the global explainer with name\n"
517-
" NoSuchExplainer in registry."
519+
"Unable to find the global explainer with name NoSuchExplainer in registry."
518520
)
519521

520522

tests/back/units/test_dataset_ingest_units.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,34 @@ def test_datafile_unit_has_its_own_wording_for_an_unknown_reader(
489489
)(ExecutionContext())
490490

491491
assert str(excinfo.value) == "DataLoader 'NoSuchLoader' not found in registry."
492+
493+
494+
def test_datafile_unit_rejects_a_component_that_is_not_a_reader(
495+
datafile_rows, csv_file, tmp_path
496+
):
497+
"""A registered component of some other kind is still not a reader.
498+
499+
The registry's ``registry[name]`` indexer searches every type at once, so
500+
looking the name up that way would find, say, a metric and call it as if it
501+
could parse a file. The lookup is deliberately scoped to the readers.
502+
"""
503+
from DashAI.back.core.enums.status import DatafileStatus
504+
from DashAI.back.dataloaders.classes.csv_dataloader import CSVDataLoader
505+
from DashAI.back.dependencies.registry import ComponentRegistry
506+
from DashAI.back.metrics.classification.accuracy import Accuracy
507+
508+
di["component_registry"] = ComponentRegistry(
509+
initial_components=[CSVDataLoader, Accuracy]
510+
)
511+
datafile_rows[7] = _DatafileRow(str(tmp_path), DatafileStatus.READY)
512+
try:
513+
with pytest.raises(JobError) as excinfo:
514+
LoadDatafileDatasetUnit(
515+
dataloader={"component": "Accuracy", "params": {}},
516+
datafile_id=7,
517+
selected_file="data.csv",
518+
)(ExecutionContext())
519+
finally:
520+
del di["component_registry"]
521+
522+
assert str(excinfo.value) == "DataLoader 'Accuracy' not found in registry."

0 commit comments

Comments
 (0)