Title: Fix get_part_of_product crash and IFC2X3 typo (#8081) by petruconduraru · Pull Request #8317 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Fix get_part_of_product crash and IFC2X3 typo (#8081) by petruconduraru · Pull Request #8317 · IfcOpenShell/IfcOpenShell
X Title: Fix get_part_of_product crash and IFC2X3 typo (#8081) by petruconduraru · Pull Request #8317 · IfcOpenShell/IfcOpenShell
Description: Fixes #8081 Credit @PahlawanJoey reported the crash and, on request, pasted the full console traceback (from Window > Toggle System Console). Those extra frames are what pinned this down to get_part_of_product. Problem Creating a door type crashed: File ".../bonsai/bim/module/model/door.py", line 99, in update_door_modifier_representation representation_data["part_of_product"] = ifcopenshell.util.representation.get_part_of_product(element, body) File ".../ifcopenshell/util/representation.py", line 443, in get_part_of_product if maps := [r for r in element.RepresentationMaps if r.MappedRepresentation.ContextOfItems == context]: TypeError: 'NoneType' object is not iterable Reproduced end to end in headless Blender: a new IFC4 project whose file has no Model/Profile/ELEVATION_VIEW context skips the elevation representation step in door.py, so the very first call into get_part_of_product hits a freshly created IfcDoorType whose RepresentationMaps is still unset. That matches Joey's frames exactly, including root/operator.py:786 and product.py:157. Two defects, both fixed RepresentationMaps is an optional IfcTypeProduct attribute (confirmed against the schema declaration for both IFC4 and IFC2X3). When unset it is None, and the list comprehension iterates it unconditionally. Fixed by returning None early, matching what the rest of the function already does when there is no match. Line 442 read element.file.schema != "IFX2X3", a typo for "IFC2X3" that has been there since this function was introduced (dc79e9e005, one commit, no later edits). Since file.schema never equals "IFX2X3", the guard always evaluated true, so IFC2X3 type products always fell into the RepresentationMaps branch, contradicting the function's own docstring ("this will return None for IFC2X3 element types"). Fixed the string. Behaviour change for existing IFC2X3 users Before this fix, an IFC2X3 type product with populated RepresentationMaps matching the context returned that map instead of None (the typo defeated the intended early return). After the fix it always returns None for IFC2X3, as documented. The only consumers are add_door_representation and the analogous window path, and both already guard on part_of_product being falsy purely to skip attaching IfcShapeAspects: if self.settings["part_of_product"]: ifcopenshell.api.geometry.add_shape_aspect(...) So for IFC2X3 the representation is still created normally, it just no longer gets Lining/Framing/Glazing shape aspects tied back to the type. That is a graceful, already-supported no-op path, not a new crash, and it is what the docstring says should happen. Verification Reproduced pre-fix and post-fix at two levels: Direct unit level: get_part_of_product on a freshly created IfcDoorType (IFC4) and IfcDoorStyle (IFC2X3) with RepresentationMaps unset raises the exact reported TypeError on the exact reported line, both before this fix. Full Blender level (headless, isolated BLENDER_USER_RESOURCES, Blender 5.2): bpy.ops.bim.add_default_type(ifc_element_type="IfcDoorType") on a fresh IFC4 project with its Model/Profile/ELEVATION_VIEW context removed reproduces Joey's traceback frame for frame, then succeeds after the fix. Confirmed the non-2X3 "has matching maps" and "no matching maps" paths are unchanged (existing behaviour preserved) with both direct calls and a normal in-app door-type creation (which already has representation maps populated by the time get_part_of_product runs, so it never hit the crash in the first place, only files missing that context did). Added test/util/test_representation.py (TestGetPartOfProduct, TestGetPartOfProductIFC2X3), 6 tests. 3 of them fail against the pre-fix code (2 crash with the reported TypeError, 1 asserts the documented IFC2X3 None behaviour); all 6 pass after both fixes. $ pytest test/util/test_representation.py -v 6 passed Lint black --check and ruff check (CI-exact toolchain) both clean on the touched files. Generated with the assistance of an AI coding tool, reviewed by Petru Conduraru.
Open Graph Description: Fixes #8081 Credit @PahlawanJoey reported the crash and, on request, pasted the full console traceback (from Window > Toggle System Console). Those extra frames are what pinned this down to get_...
X Description: Fixes #8081 Credit @PahlawanJoey reported the crash and, on request, pasted the full console traceback (from Window > Toggle System Console). Those extra frames are what pinned this down to ...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/pull/8317
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6f9ce915-33e5-cb93-53c7-4e68fc25dfb3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BC32:99B56:91FA3E:CC5F5B:6B0483E9 |
| html-safe-nonce | ba9b7cd0eddb338fdbb45fa25391679d34b8433408c704e12ce6902a555a5f8e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzMyOjk5QjU2OjkxRkEzRTpDQzVGNUI6NkIwNDgzRTkiLCJ2aXNpdG9yX2lkIjoiMTU4Mzc2MzcwNzUyMjIyMTAzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 90b8f041d405d472021ed71b5ec3786959d66af5048b7988f2bb3f6895aab5a3 |
| hovercard-subject-tag | pull_request:3998315613 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/IfcOpenShell/IfcOpenShell/pull/8317/files |
| twitter:image | https://avatars.githubusercontent.com/u/139251053?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/139251053?s=400&v=4 |
| og:image:alt | Fixes #8081 Credit @PahlawanJoey reported the crash and, on request, pasted the full console traceback (from Window > Toggle System Console). Those extra frames are what pinned this down to get_... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d5c152376e38b7d2e37f3d5179be29a73bee93b85110da28a4eebe1159cdc70 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f5017e8ff4ea25a8011fcf0f2a0e430c60dc86c8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width