mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-05 23:41:44 +00:00
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
This commit is contained in:
committed by
Dion Moult
parent
aafa1b95e8
commit
a3801a0ce9
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user