Title: project.append_asset: AssertionError in SafeRemovalContext.__exit__ when removing an untracked element · Issue #8666 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: project.append_asset: AssertionError in SafeRemovalContext.__exit__ when removing an untracked element · Issue #8666 · IfcOpenShell/IfcOpenShell
X Title: project.append_asset: AssertionError in SafeRemovalContext.__exit__ when removing an untracked element · Issue #8666 · IfcOpenShell/IfcOpenShell
Description: Describe the bug ifcopenshell.api.project.append_asset can abort with an uncaught AssertionError inside SafeRemovalContext.__exit__ while appending a product asset (with the default assume_asset_uniqueness_by_name=True): File ".../ifcope...
Open Graph Description: Describe the bug ifcopenshell.api.project.append_asset can abort with an uncaught AssertionError inside SafeRemovalContext.__exit__ while appending a product asset (with the default assume_asset_un...
X Description: Describe the bug ifcopenshell.api.project.append_asset can abort with an uncaught AssertionError inside SafeRemovalContext.__exit__ while appending a product asset (with the default assume_asset_un...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/8666
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"project.append_asset: AssertionError in SafeRemovalContext.__exit__ when removing an untracked element","articleBody":"### Describe the bug\n\n`ifcopenshell.api.project.append_asset` can abort with an uncaught `AssertionError` inside `SafeRemovalContext.__exit__` while appending a product asset (with the default `assume_asset_uniqueness_by_name=True`):\n\n```\n File \".../ifcopenshell/api/project/append_asset.py\", line 420, in append_product\n with SafeRemovalContext(self.file, self.reuse_identities, self.assume_asset_uniqueness_by_name):\n File \".../ifcopenshell/api/project/append_asset.py\", line 188, in __exit__\n assert len(removed_identities) == len(removed_elements)\nAssertionError\n```\n\nThe `SafeRemovalContext` wraps the `edit_object_placement` call in `append_product`. It batches `remove_deep2` deletions into `file.to_delete`, and on exit asserts that **every** removed element is tracked in `reuse_identities`:\n\n```python\nremoved_elements = self.file.to_delete\nfor identity, element in self.reuse_identities.items():\n if element in removed_elements:\n removed_identities[element] = identity\nassert len(removed_identities) == len(removed_elements)\n```\n\n### Analysis\n\n`remove_deep2` only ever purges an element when *all* of its inverses lie inside the subgraph being deleted. Therefore a removed element that is **not** tracked in `reuse_identities` cannot be referenced by any surviving `reuse_identities` value, and needs no cleanup. The equality `assert` nevertheless turns this benign case into a hard crash and aborts the whole append.\n\nThe cleanup that actually matters — purging `reuse_identities` entries whose value was removed, so the map never later returns a freed entity — already works correctly for the tracked subset, independent of whether untracked removals also occurred.\n\n### Suggested fix\n\nDrop the equality assertion. Continue collecting and cleaning up the tracked identities, and simply ignore untracked removed elements (they are provably safe to remove). i.e. remove the `assert len(removed_identities) == len(removed_elements)` line; the rest of `__exit__` is unchanged.\n\n### Reproduction\n\nEncountered when appending a product (an `IfcFurniture`/equipment asset with geometry) from a library into an **existing populated** project. A self-contained minimal reproduction is still being narrowed down — the trigger is an asset whose object-placement subgraph, during `edit_object_placement`'s `remove_deep2`, purges an element that was not registered in `reuse_identities`. Guidance on which asset shape reliably produces an untracked placement removal would be welcome.\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/8666"}
| 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:a1ecea77-e2b6-0b7a-646f-3470c5e917b4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A264:29F525:1DA943:27D0F4:6B04833B |
| html-safe-nonce | 45df13af70307b2470561e33b92dd165642b5d7f8016f7b1a236ccf194111945 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjY0OjI5RjUyNToxREE5NDM6MjdEMEY0OjZCMDQ4MzNCIiwidmlzaXRvcl9pZCI6Ijg1ODY0MDA4MTA2Njg0MjYwNDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2bab13b0e8f144becdbe5079c72c82437cd527486c71ac32f6f53cc91b2451d8 |
| hovercard-subject-tag | issue:4907574166 |
| 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/8666/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6dc3ad2811f73e22e4ea018a6f1cbd34de2f1ce9ff90ae5364b148b6b3853395/IfcOpenShell/IfcOpenShell/issues/8666 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6dc3ad2811f73e22e4ea018a6f1cbd34de2f1ce9ff90ae5364b148b6b3853395/IfcOpenShell/IfcOpenShell/issues/8666 |
| og:image:alt | Describe the bug ifcopenshell.api.project.append_asset can abort with an uncaught AssertionError inside SafeRemovalContext.__exit__ while appending a product asset (with the default assume_asset_un... |
| 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