Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion pyxform/entities/entities_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def validate_entities_columns(row: dict):
def validate_entity_repeat_target(
entity_declaration: dict[str, Any] | None,
stack: Sequence[dict[str, Any]] | None = None,
repeat_names: set[str] | None = None,
) -> bool:
"""
Check if the entity repeat target exists, is a repeat, and is a name match.
Expand All @@ -355,6 +356,7 @@ def validate_entity_repeat_target(

:param entity_declaration:
:param stack: The control stack from workbook_to_json.
:param repeat_names: Set of all repeat names found in the survey sheet.
:return:
"""
# Ignore: entity already processed.
Expand All @@ -368,8 +370,15 @@ def validate_entity_repeat_target(
return False

# Error: repeat not found while processing survey sheet.
# When stack is None (end of processing), check against repeat_names set.
if not stack:
raise PyXFormError(ENTITY002.format(value=entity_repeat))
# If repeat_names is provided, check if the entity repeat exists in the set
if repeat_names is not None:
if entity_repeat not in repeat_names:
raise PyXFormError(ENTITY002.format(value=entity_repeat))
else:
# Fall back to original behavior if repeat_names not provided
raise PyXFormError(ENTITY002.format(value=entity_repeat))

control_name = stack[-1]["control_name"]
control_type = stack[-1]["control_type"]
Expand Down
4 changes: 3 additions & 1 deletion pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,9 @@ def workbook_to_json(
)

if entity_declaration:
validate_entity_repeat_target(entity_declaration=entity_declaration)
validate_entity_repeat_target(
entity_declaration=entity_declaration, repeat_names=repeat_names
)
json_dict[constants.ENTITY_VERSION] = constants.EntityVersion.v2024_1_0
meta_children.append(entity_declaration)

Expand Down