From a3801a0ce96ef42f5b1819705309ddf6b15163a2 Mon Sep 17 00:00:00 2001 From: Vincent Cadoret Date: Wed, 24 Dec 2025 16:22:26 -0500 Subject: [PATCH] Fix UnboundLocalError in reporter.py cardinality assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/ifctester/ifctester/reporter.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ifctester/ifctester/reporter.py b/src/ifctester/ifctester/reporter.py index 220d0f96a9..84684a10a2 100644 --- a/src/ifctester/ifctester/reporter.py +++ b/src/ifctester/ifctester/reporter.py @@ -367,6 +367,12 @@ class Json(Reporter): cardinality = "optional" elif specification.minOccurs == 0 and specification.maxOccurs == 0: cardinality = "prohibited" + elif specification.minOccurs >= 1: + # Any minimum occurrence >= 1 means the specification is required + cardinality = "required" + else: + # minOccurs == 0 with any other maxOccurs value means optional + cardinality = "optional" return ResultsSpecification( name=specification.name,