Title: Bonsai: Update Representation fails on a type object with a stale mesh · Issue #10099 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Bonsai: Update Representation fails on a type object with a stale mesh · Issue #10099 · IfcOpenShell/IfcOpenShell
X Title: Bonsai: Update Representation fails on a type object with a stale mesh · Issue #10099 · IfcOpenShell/IfcOpenShell
Description: Bug Description Update Representation on an occurrence can fail with an AssertionError in _reload_representation, depending on the order objects happen to be reloaded in. It happens when the occurrence and its type object each hold their...
Open Graph Description: Bug Description Update Representation on an occurrence can fail with an AssertionError in _reload_representation, depending on the order objects happen to be reloaded in. It happens when the occurr...
X Description: Bug Description Update Representation on an occurrence can fail with an AssertionError in _reload_representation, depending on the order objects happen to be reloaded in. It happens when the occurr...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/10099
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bonsai: Update Representation fails on a type object with a stale mesh","articleBody":"### Bug Description\n\n**Update Representation** on an occurrence can fail with an `AssertionError` in `_reload_representation`, depending on the order objects happen to be reloaded in. It happens when the occurrence and its type object each hold their own Blender mesh.\n\n1. `update_obj_mesh_representation` relinks the occurrence's mesh to the new representation, then removes the old one. The type object's mesh still holds the removed id.\n2. `reload_representation` collects both objects into a `set`, then reloads each of them.\n3. Reloading the occurrence would repair the type, because `reimport_element_representations` also refreshes the occurrence's type.\n4. If the type object comes first, `get_active_representation` returns `None` and `assert representation` fails, so the repair never runs.\n\nThe IFC has already changed by that point, so the type's mesh stays stale. In my model it had an open Representation Items list, which later crashed **Save IFC** with `RuntimeError: Instance #N not found` (see #8906).\n\nEvidence from my model: of 2,702 objects, exactly one mesh pointed at a removed representation. It was the type object's mesh, while its occurrence's mesh pointed at the replacement representation.\n\nI don't know why the two objects had separate meshes. The type's representation in my model is a map of a map, which may or may not be related. I also inferred that this failure is how the mesh first went stale; the saved files only show the end result.\n\n### Reproduction\n\nThe bug can be reproduced without a model. Give an occurrence and its type separate meshes, make the type's mesh id stale, and call `tool.Geometry.reload_representation(occurrence_obj)`. Because of the `set`, it fails only some of the time: 6 of 10 runs in my test.\n\n### Proposed fix\n\nSkip objects with no live representation in the `reload_representation` loop, so the occurrence's reload repairs them:\n\n```python\nfor obj in meshes_to_objects.values():\n if cls.get_active_representation(obj):\n cls._reload_representation(obj)\n```\n\nWith this change, the regression test passed 10 of 10 runs and all 67 tests in `test/tool/test_geometry.py` passed (Blender 5.1.2). The test checks that the type's mesh ends up pointing at the live representation. It uses a plain type and occurrence, not the nested map, and I haven't yet tried the fix in the original model through the UI.\n\n### Related\n\n- #10053 has the same call path (`update_representation` → `reload_representation` → `_reload_representation`) and was closed as fixed by 55428a0878. That commit makes `get_active_representation` return `None` for a stale id, so on a current build the same path would stop at the `assert`, as here. I can't confirm #10053 had the same cause.\n- #8906 guards other stale-id lookups, including the one behind the Save IFC crash, but not this loop.\n\n### Attachments\n\nNone needed for the reproduction above.\n\n### Debug and Error Output\n\n```\nblender_version: 5.1.2\nbonsai_commit_hash: 61a0819\nbonsai_git_branch: Frankenstein_build-0.9.0-alpha2610112324 (v0.9.0-based; v0.9.0 has the same loop)\n\nTraceback (most recent call last):\n File \"bonsai\\bim\\ifc.py\", line 450, in execute_ifc_operator\n result = getattr(operator, \"_execute\")(context)\n File \"bonsai\\bim\\module\\geometry\\operator.py\", line 661, in _execute\n tool.Geometry.reload_representation(objs)\n File \"bonsai\\tool\\geometry.py\", line 1895, in reload_representation\n cls._reload_representation(obj)\n File \"bonsai\\tool\\geometry.py\", line 1908, in _reload_representation\n assert representation\nAssertionError\n```\n\nInvestigation and proposed fix generated with the assistance of an AI coding tool.\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-10-30T16:09:52Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/10099"}
| 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:e4614ffa-a418-25fd-155e-263cce326313 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9436:E08F0:17F6AD:21D2C9:6B04667A |
| html-safe-nonce | f229957db6f22a2c0c34f19ea453b0c0dbfc59f727c748c1bca2405cb0cee1e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDM2OkUwOEYwOjE3RjZBRDoyMUQyQzk6NkIwNDY2N0EiLCJ2aXNpdG9yX2lkIjoiODE0MTkyMDA0ODI3NDIzNzA1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5aebb8c2ed45b50c81aba078b00959a495197bb016790876814a60ba447c6f75 |
| hovercard-subject-tag | issue:6122640274 |
| 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/10099/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1f6fd00a83a563191c1b60cee759f40c871cd2e5300710cb5a96ca504ef3a417/IfcOpenShell/IfcOpenShell/issues/10099 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1f6fd00a83a563191c1b60cee759f40c871cd2e5300710cb5a96ca504ef3a417/IfcOpenShell/IfcOpenShell/issues/10099 |
| og:image:alt | Bug Description Update Representation on an occurrence can fail with an AssertionError in _reload_representation, depending on the order objects happen to be reloaded in. It happens when the occurr... |
| 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 | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| 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 | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| 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