Title: project.append_asset: TypeError aborts entire append when a library type's GlobalId collides with a different-class element in the destination · Issue #8667 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: project.append_asset: TypeError aborts entire append when a library type's GlobalId collides with a different-class element in the destination · Issue #8667 · IfcOpenShell/IfcOpenShell
X Title: project.append_asset: TypeError aborts entire append when a library type's GlobalId collides with a different-class element in the destination · Issue #8667 · IfcOpenShell/IfcOpenShell
Description: Describe the bug When project.append_asset appends a product whose type's GlobalId collides with an element of a different class already present in the destination file, the entire append aborts with: File ".../ifcopenshell/api/project/a...
Open Graph Description: Describe the bug When project.append_asset appends a product whose type's GlobalId collides with an element of a different class already present in the destination file, the entire append aborts wi...
X Description: Describe the bug When project.append_asset appends a product whose type's GlobalId collides with an element of a different class already present in the destination file, the entire append abort...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/8667
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"project.append_asset: TypeError aborts entire append when a library type's GlobalId collides with a different-class element in the destination","articleBody":"### Describe the bug\n\nWhen `project.append_asset` appends a product whose **type**'s `GlobalId` collides with an element of a *different class* already present in the destination file, the entire append aborts with:\n\n```\n File \".../ifcopenshell/api/project/append_asset.py\", line 449, in append_product\n ifcopenshell.api.type.assign_type(\n File \".../ifcopenshell/api/type/assign_type.py\", line 213, in execute\n raise TypeError(\nTypeError: IfcFlowTerminal cannot type IfcSanitaryTerminal in schema IFC4 (allowed occurrence classes: \u003cnone>)\n```\n\nThis only happens when appending into an existing (populated) file, never into a blank one.\n\n### Root cause\n\n`Usecase.get_existing_element` reuses any `IfcRoot` purely by `GlobalId`, regardless of class:\n\n```python\nif element.is_a(\"IfcRoot\"):\n return self.by_guid(element.GlobalId)\n```\n\nIn `append_product`, the occurrence's type is appended recursively and the resulting entity passed to `assign_type`. If the library type's `GlobalId` already exists in the destination on an unrelated element (e.g. an `IfcFlowTerminal` occurrence), `get_existing_element` returns that occurrence as the \"type\". `assign_type` then correctly rejects an occurrence-classed entity as a `RelatingType`, raising `TypeError` — which aborts the whole batch append and leaves the model partially modified.\n\n### Minimal reproduction\n\n```python\nimport ifcopenshell\nimport ifcopenshell.api.root, ifcopenshell.api.context\nimport ifcopenshell.api.project, ifcopenshell.api.unit, ifcopenshell.api.type\n\ndef new_file(name):\n f = ifcopenshell.file(schema=\"IFC4\")\n ifcopenshell.api.root.create_entity(f, ifc_class=\"IfcProject\", name=name)\n unit = ifcopenshell.api.unit.add_si_unit(f, unit_type=\"LENGTHUNIT\")\n ifcopenshell.api.unit.assign_unit(f, units=[unit])\n ifcopenshell.api.context.add_context(f, context_type=\"Model\")\n return f\n\nlibrary = new_file(\"Lib\")\nocc = ifcopenshell.api.root.create_entity(library, ifc_class=\"IfcSanitaryTerminal\")\ntyp = ifcopenshell.api.root.create_entity(library, ifc_class=\"IfcSanitaryTerminalType\")\nifcopenshell.api.type.assign_type(library, related_objects=[occ], relating_type=typ)\n\nproject = new_file(\"Dest\")\n# destination already contains an unrelated element sharing the library type's GlobalId\nft = ifcopenshell.api.root.create_entity(project, ifc_class=\"IfcFlowTerminal\")\nft.GlobalId = typ.GlobalId\n\nifcopenshell.api.project.append_asset(project, library=library, element=occ)\n# -> TypeError: IfcFlowTerminal cannot type IfcSanitaryTerminal in schema IFC4 (allowed occurrence classes: \u003cnone>)\n```\n\n### Suggested fixes (either or both)\n\n1. In `get_existing_element`, only reuse a by-`GlobalId` match when the class is compatible (`existing.is_a(element.is_a())`). A cross-class GUID match is a collision and should not be treated as the same asset.\n2. In `append_product`, guard the `assign_type` call so a single colliding/malformed asset does not abort the whole batch — append the occurrence untyped and emit a warning instead of raising.\n\n### Impact\n\nA single duplicated `GlobalId` anywhere across a large library/destination pair aborts the *entire* multi-asset append, leaving a partially-modified model. This is realistic with Revit-exported IFC content where GlobalIds are sometimes reused across entities.\n\n### Environment\n\n- ifcopenshell (bundled with Bonsai on Blender 4.5), schema IFC4, `v0.8.0` branch.\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-07-17T02:39:43Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/8667"}
| 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 | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e0d1a3fa-17fc-814a-02ea-29badffb5038 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D838:281ABB:A81B4A:E56A1D:6B048340 |
| html-safe-nonce | e95ba2890266d9bf6dac1a1ab2720d8716c5e5aefb1cef7b9c82d037d9552516 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODM4OjI4MUFCQjpBODFCNEE6RTU2QTFEOjZCMDQ4MzQwIiwidmlzaXRvcl9pZCI6IjgwODAwMDMzMDU4MTM4NjkzNzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3c7779267824f4d15de8dd0b4634a6268384ad908f40cc9ab5c0cd01f0d7d8e9 |
| hovercard-subject-tag | issue:4907574227 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/8667/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2c8dc773793c393fd4c5ffbb8db1e9fa0da901ee32102a3df2a18f704428a346/IfcOpenShell/IfcOpenShell/issues/8667 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2c8dc773793c393fd4c5ffbb8db1e9fa0da901ee32102a3df2a18f704428a346/IfcOpenShell/IfcOpenShell/issues/8667 |
| og:image:alt | Describe the bug When project.append_asset appends a product whose type's GlobalId collides with an element of a different class already present in the destination file, the entire append aborts wi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | theoryshaw |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d5c152376e38b7d2e37f3d5179be29a73bee93b85110da28a4eebe1159cdc70 |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| 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 |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width