Skip to content

Commit b4686fc

Browse files
committed
Fix all_required_children_are_set
1 parent d632535 commit b4686fc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

pynxtools/dataconverter/helpers.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,17 @@ def is_node_required(nxdl_key, nxdl_root):
432432

433433
def all_required_children_are_set(optional_parent_path, data, nxdl_root):
434434
"""Walks over optional parent's children and makes sure all required ones are set"""
435-
optional_parent_path = convert_data_converter_dict_to_nxdl_path(
436-
optional_parent_path
437-
)
438435
for key in data:
439436
if key in data["lone_groups"]:
440437
continue
441438
nxdl_key = convert_data_converter_dict_to_nxdl_path(key)
439+
name = nxdl_key[nxdl_key.rfind("/") + 1 :]
440+
renamed_path = f"{optional_parent_path}/{name}"
442441
if (
443-
nxdl_key[0 : nxdl_key.rfind("/")] == optional_parent_path
442+
nxdl_key[: nxdl_key.rfind("/")]
443+
== convert_data_converter_dict_to_nxdl_path(optional_parent_path)
444444
and is_node_required(nxdl_key, nxdl_root)
445-
and data[path_in_data_dict(nxdl_key, tuple(data.keys()))[1]] is None
445+
and (renamed_path not in data or data[renamed_path] is None)
446446
):
447447
return False
448448

@@ -460,12 +460,19 @@ def is_nxdl_path_a_child(nxdl_path: str, parent: str):
460460

461461
def check_optionality_based_on_parent_group(path, nxdl_path, nxdl_root, data, template):
462462
"""Checks whether field is part of an optional parent and then confirms its optionality"""
463+
464+
def trim_path_to(parent: str, path: str):
465+
count = len(parent.split("/"))
466+
return "/".join(path.split("/")[:count])
467+
463468
for optional_parent in template["optional_parents"]:
464469
optional_parent_nxdl = convert_data_converter_dict_to_nxdl_path(optional_parent)
465470
if is_nxdl_path_a_child(
466471
nxdl_path, optional_parent_nxdl
467-
) and not all_required_children_are_set(optional_parent, data, nxdl_root):
468-
raise LookupError(
472+
) and not all_required_children_are_set(
473+
trim_path_to(optional_parent, path), data, nxdl_root
474+
):
475+
logger.warning(
469476
f"The data entry, {path}, has an optional parent, "
470477
f"{optional_parent}, with required children set. Either"
471478
f" provide no children for {optional_parent} or provide"

0 commit comments

Comments
 (0)