Skip to content

Commit

Permalink
better error msg for incomplete mapping (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
subbyte authored Jun 14, 2024
1 parent abe19d9 commit f3d4eca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
12 changes: 9 additions & 3 deletions packages/kestrel_core/src/kestrel/mapping/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ def load_default_mapping(

@typechecked
def check_entity_identifier_existence_in_mapping(
data_model_mapping: dict, entity_identifiers: dict
data_model_mapping: dict,
entity_identifiers: dict,
interface_information: Optional[str] = None,
):
for entity_name, ids in entity_identifiers.items():
if entity_name in data_model_mapping:
Expand All @@ -239,9 +241,13 @@ def check_entity_identifier_existence_in_mapping(
try:
reduce(dict.__getitem__, idx.split("."), entity)
except KeyError:
raise IncompleteDataMapping(
f"Identifier '{idx}' missing in data mapping"
msg_body = f"Identifier '{idx}' for entity '{entity_name}' is missing in data mapping"
appendix = (
f" at '{interface_information}'"
if interface_information
else ""
)
raise IncompleteDataMapping(msg_body + appendix)


@typechecked
Expand Down
2 changes: 1 addition & 1 deletion packages/kestrel_core/tests/test_mapping_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ def test_translate_dataframe(): #TODO: more testing here
def test_incomplete_mapping_no_identifier():
identifier_config = load_kestrel_config()["entity_identifier"]
with pytest.raises(IncompleteDataMapping):
check_entity_identifier_existence_in_mapping(INCOMPLETE_MAPPING, identifier_config)
check_entity_identifier_existence_in_mapping(INCOMPLETE_MAPPING, identifier_config, "test interface")
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def __post_init__(self):

kestrel_config = load_kestrel_config()
check_entity_identifier_existence_in_mapping(
self.data_model_map, kestrel_config["entity_identifier"]
self.data_model_map,
kestrel_config["entity_identifier"],
"opensearch interface",
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def __post_init__(self):

kestrel_config = load_kestrel_config()
check_entity_identifier_existence_in_mapping(
self.data_model_map, kestrel_config["entity_identifier"]
self.data_model_map,
kestrel_config["entity_identifier"],
"sqlalchemy interface",
)


Expand Down

0 comments on commit f3d4eca

Please sign in to comment.