Skip to content

Commit a3801a0

Browse files
vincentqcgMoult
authored andcommitted
Fix UnboundLocalError in reporter.py cardinality assignment
The report_specification() method in the Json reporter class was raising an UnboundLocalError when processing IDS specifications with certain minOccurs/maxOccurs combinations that weren't explicitly handled. Problem: The cardinality variable was only assigned for three specific cases: - minOccurs=1, maxOccurs="unbounded" → "required" - minOccurs=0, maxOccurs="unbounded" → "optional" - minOccurs=0, maxOccurs=0 → "prohibited" However, the IDS schema allows other valid combinations such as: - minOccurs=0, maxOccurs=1 (commonly used for optional specifications) - minOccurs=1, maxOccurs=1 (exactly one occurrence required) - Any other valid XML Schema cardinality values When processing IDS files with these combinations, the cardinality variable remained unassigned, causing an UnboundLocalError at line 382 when attempting to use it in ResultsSpecification(). Solution: Added fallback logic to handle all valid IDS cardinality combinations: - If minOccurs >= 1: cardinality = "required" (must occur at least once) - Otherwise (minOccurs == 0): cardinality = "optional" (may occur) This maintains semantic compatibility with the existing codebase, which expects cardinality to be one of the semantic strings ("required", "optional", "prohibited") rather than numeric ranges. This is critical for: - HTML template rendering (line 457: .capitalize()) - Conditional logic for skipped specs (line 454) - UI rendering for prohibited specs (line 456) Testing: - Tested with IDS file containing minOccurs=0 without explicit maxOccurs (defaults to 1 per XML Schema specification) - Validation now completes successfully without UnboundLocalError - HTML report generation works correctly with semantic cardinality labels - Maintains backward compatibility with existing IDS files Fixes: Validation failure when using valid IDS cardinality combinations
1 parent aafa1b9 commit a3801a0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/ifctester/ifctester/reporter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ def report_specification(self, specification: Specification) -> ResultsSpecifica
367367
cardinality = "optional"
368368
elif specification.minOccurs == 0 and specification.maxOccurs == 0:
369369
cardinality = "prohibited"
370+
elif specification.minOccurs >= 1:
371+
# Any minimum occurrence >= 1 means the specification is required
372+
cardinality = "required"
373+
else:
374+
# minOccurs == 0 with any other maxOccurs value means optional
375+
cardinality = "optional"
370376

371377
return ResultsSpecification(
372378
name=specification.name,

0 commit comments

Comments
 (0)