Skip to content

fix: Correct PSE001 validation for Python literals and empty enumerations#512

Open
VDobranov wants to merge 53 commits intobuildingSMART:developmentfrom
VDobranov:main
Open

fix: Correct PSE001 validation for Python literals and empty enumerations#512
VDobranov wants to merge 53 commits intobuildingSMART:developmentfrom
VDobranov:main

Conversation

@VDobranov
Copy link
Copy Markdown

For Info

The fix was created with the help of Qwen AI.

Summary

This PR fixes two bugs in the PSE001 validation rule that caused false positive errors when validating IFC files with Pset_ElementComponentCommon.

Issues Fixed

Bug 1: CSV parsing error for Python literals

File: features/steps/steps/propertysets_qtys_units.py, function make_obj()

Problem: The parser used json.loads(s.replace("'", '"')) to parse Python dictionary literals from pset_definitions.csv. This failed for Python constants like None, True, False which are not valid JSON.

Error message:

json.decoder.JSONDecodeError: Expecting value: line 1 column 461 (char 460)

Fix: Use ast.literal_eval() for proper Python literal parsing, with fallback to JSON parsing for compatibility:

def make_obj(s):
    if s:
        import ast
        try:
            return ast.literal_eval(s)  # Proper Python literal parsing
        except (ValueError, SyntaxError):
            return json.loads(s.replace("'", '"'))  # Fallback for JSON
    else:
        return ''

Bug 2: Empty enumeration values validation

File: features/steps/steps/propertysets_qtys_units.py, function step_impl()

Problem: Empty values list values: [] in pset template was interpreted as "only empty value allowed", but should mean "any value is accepted" (open enumeration).

Error message:

ValidationOutcome.OutcomeCode.VALUE_ERROR
expected=FrozenDict({'value': ()}), observed=FrozenDict({'value': 'LOOSE'})

Fix: Skip validation when accepted_data_type['values'] is empty:

if accepted_data_type['values']:  # Only check if list is not empty
    for value in values:
        if not value.wrappedValue in accepted_data_type['values']:
            yield ValidationOutcome(...)
# If empty, any value is valid (no check needed)

rw-bsi and others added 30 commits August 30, 2024 19:16
* disable BRP001

* disable TAS001
* Fix SWE001

* Version bump

---------

Co-authored-by: Thomas Krijnen <[email protected]>
* Add material/profile properties to whitelisted inverses buildingSMART#356

* Update scenario text and version bump

* Also fix IfcMaterialDefinitionRepresentation
@aothms
Copy link
Copy Markdown
Collaborator

aothms commented Mar 31, 2026

Hi, maybe you shared this elsewhere but do you have an example file that triggers this behaviour?

@VDobranov
Copy link
Copy Markdown
Author

VDobranov commented Mar 31, 2026

Hi, maybe you shared this elsewhere but do you have an example file that triggers this behaviour?

Hi! Sure, I'm adding the file (don't see anything special about it, though):
bolt_1.1_M20x800.ifc.txt

Also, here are two results (before and after fix) of the command:
python -m behave --define input=$IFC_FILE features/rules/PSE/PSE001_*.feature
tst.txt
tst2.txt

I am a bit unsure whether it is AI's voodoo or genuine bug, but according to my tests it seems legit.

	modified:   features/steps/utils/geometry.py
@civilx64 civilx64 changed the base branch from main to development April 1, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants