4141 name = "Invalid entity repeat save_to: question in nested repeat" ,
4242 msg = (
4343 "[row : {row}] On the 'survey' sheet, the 'save_to' value '{value}' is invalid. "
44- "The entity properties populated with 'save_to' must not be inside of a nested "
44+ "The entity property populated with 'save_to' must not be inside of a nested "
4545 "repeat within the entity repeat."
4646 ),
4747)
4848ENTITY006 = Detail (
4949 name = "Invalid entity repeat save_to: question not in entity repeat" ,
5050 msg = (
5151 "[row : {row}] On the 'survey' sheet, the 'save_to' value '{value}' is invalid. "
52- "The entity properties populated with 'save_to' must be inside of the entity "
52+ "The entity property populated with 'save_to' must be inside of the entity "
5353 "repeat."
5454 ),
5555)
56+ ENTITY007 = Detail (
57+ name = "Invalid entity repeat save_to: question in repeat but no entity repeat defined" ,
58+ msg = (
59+ "[row : {row}] On the 'survey' sheet, the 'save_to' value '{value}' is invalid. "
60+ "The entity property populated with 'save_to' must be inside a repeat that is "
61+ "declared in the 'repeat' column of the 'entities' sheet."
62+ ),
63+ )
5664
5765
5866def get_entity_declaration (
@@ -244,8 +252,8 @@ def get_validated_repeat_name(entity) -> str | None:
244252def validate_entity_saveto (
245253 row : dict ,
246254 row_number : int ,
255+ stack : Sequence [dict [str , Any ]],
247256 entity_declaration : dict [str , Any ] | None = None ,
248- stack : Sequence [dict [str , Any ]] | None = None ,
249257):
250258 save_to = row .get (const .BIND , {}).get ("entities:saveto" , "" )
251259 if not save_to :
@@ -262,23 +270,26 @@ def validate_entity_saveto(
262270 )
263271
264272 entity_repeat = entity_declaration .get (EC .REPEAT , None )
265- if entity_repeat and stack :
266- # Error: saveto in nested repeat inside entity repeat.
267- in_repeat = False
268- located = False
269- for i in reversed (stack ):
270- if not i ["control_name" ] or not i ["control_type" ]:
271- break
272- elif i ["control_type" ] == const .REPEAT :
273- if in_repeat :
274- raise PyXFormError (ENTITY005 .format (row = row_number , value = save_to ))
275- elif i ["control_name" ] == entity_repeat :
276- located = True
277- in_repeat = True
278-
279- # Error: saveto not in entity repeat
280- if not located :
281- raise PyXFormError (ENTITY006 .format (row = row_number , value = save_to ))
273+ in_repeat = False
274+ located = False
275+ for i in reversed (stack ):
276+ if not i ["control_name" ] or not i ["control_type" ]:
277+ break
278+ elif i ["control_type" ] == const .REPEAT :
279+ # Error: saveto in nested repeat inside entity repeat.
280+ if in_repeat :
281+ raise PyXFormError (ENTITY005 .format (row = row_number , value = save_to ))
282+ elif i ["control_name" ] == entity_repeat :
283+ located = True
284+ in_repeat = True
285+
286+ # Error: saveto not in entity repeat
287+ if entity_repeat and not located :
288+ raise PyXFormError (ENTITY006 .format (row = row_number , value = save_to ))
289+
290+ # Error: saveto in repeat but no entity repeat declared
291+ if in_repeat and not entity_repeat :
292+ raise PyXFormError (ENTITY007 .format (row = row_number , value = save_to ))
282293
283294 error_start = f"{ const .ROW_FORMAT_STRING % row_number } Invalid save_to name:"
284295
0 commit comments