Title: Refresh Linked Aggregate crashes on a nested assembly that isn't a linked aggregate · Issue #9582 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Refresh Linked Aggregate crashes on a nested assembly that isn't a linked aggregate · Issue #9582 · IfcOpenShell/IfcOpenShell
X Title: Refresh Linked Aggregate crashes on a nested assembly that isn't a linked aggregate · Issue #9582 · IfcOpenShell/IfcOpenShell
Description: Bug Description bim.refresh_linked_aggregate crashes with StopIteration when a linked aggregate contains a nested IfcElementAssembly that is not itself a linked aggregate. To reproduce: Have several linked aggregates in the model. Select...
Open Graph Description: Bug Description bim.refresh_linked_aggregate crashes with StopIteration when a linked aggregate contains a nested IfcElementAssembly that is not itself a linked aggregate. To reproduce: Have severa...
X Description: Bug Description bim.refresh_linked_aggregate crashes with StopIteration when a linked aggregate contains a nested IfcElementAssembly that is not itself a linked aggregate. To reproduce: Have severa...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9582
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Refresh Linked Aggregate crashes on a nested assembly that isn't a linked aggregate","articleBody":"### Bug Description\n\n`bim.refresh_linked_aggregate` crashes with `StopIteration` when a linked aggregate contains a nested `IfcElementAssembly` that is not itself a linked aggregate.\n\n**To reproduce:**\n\n1. Have several linked aggregates in the model.\n2. Select them all (the assembly empties *and* their parts).\n3. `Add Aggregate` (`bim.add_aggregate`) to wrap the whole selection in a new aggregate.\n4. Duplicate that new aggregate (which promotes it to a linked aggregate).\n5. Run `Refresh Linked Aggregate` on it → `StopIteration`.\n\n**Root cause**\n\n`get_original_data` in `src/bonsai/bonsai/bim/module/geometry/operator.py` starts with a bare `next()` with no default:\n\n```python\ndef get_original_data(element):\n group: int = next(\n r.RelatingGroup\n for r in getattr(element, \"HasAssignments\", []) or []\n if r.is_a(\"IfcRelAssignsToGroup\")\n if self.group_name in r.RelatingGroup.Name\n ).id()\n```\n\nAt the top level this is safe — `handle_selection` does the same lookup inside a `try/except` and bails with *\"Object is not part of a Linked Aggregate\"*. But the **recursive** call is unguarded:\n\n```python\nparts = ifcopenshell.util.element.get_parts(element)\nif parts:\n for part in parts:\n if part.is_a(\"IfcElementAssembly\"):\n nested_data = get_original_data(part) # \u003c-- no guard\n```\n\nSo the operator assumes *every nested `IfcElementAssembly` inside a linked aggregate is itself a linked aggregate*. Any nested assembly without a `BBIM_Linked_Aggregate` group assignment raises `StopIteration` instead of being skipped.\n\n**Why the repro produces that shape**\n\n`BIM_OT_add_aggregate._execute` creates a bare `IfcElementAssembly` and re-parents the selection under it. It never assigns a `BBIM_Linked_Aggregate` group or pset, so wrapping linked aggregates this way is a first-class way to create nested assemblies that violate the assumption above.\n\n**Related weak spots in the same function**\n\n- `select_objects_and_add_data` only calls `add_linked_aggregate_pset(element, ...)` when the element **has parts**, so an empty nested assembly gets a group but no pset, and later dies on `pset[\"Index\"]` — the same failure as #4435.\n- `delete_objects` also recurses into nested assemblies unconditionally and deletes them, so refresh over a nested structure is risky beyond this crash.\n\n**Note on PR #8319**\n\n#8319 (for #8233) makes plain duplicates re-join the same `BBIM_Linked_Aggregate` group. That grows `get_group_elements`, so more elements land in `instances_to_refresh` and get recursed into — it likely makes this crash easier to hit. Worth reviewing the two together.\n\nVerified present on `v0.9.0` as well (the `next()` is unchanged there).\n\n### Attachments\n\nNone. The crash happened with unsaved changes, so the saved IFC predates the\nfailing state; the traceback and the structure that triggers it are below.\n\n### Debug and Error Output\n\n```true\nos: Windows\nos_version: 10.0.19045\npython_version: 3.13.13\narchitecture: ('64bit', 'WindowsPE')\nmachine: AMD64\nprocessor: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel\nblender_version: 5.2.1 LTS\nbonsai_version: 0.0.0\nbonsai_commit_hash: 8ffab9d\nbonsai_commit_date: 2026-09-23T09:44:15-05:00\nbonsai_git_branch: Ryan_build-0.8.6-alpha2607071335\nlast_actions: \n# ifcopenshell.api: owner.update_owner_history\n>>> {\"element\": {\"cast_type\": \"entity_instance\", \"value\": 4120503, \"Name\": \"Beam.035\"}}\n# ifcopenshell.api: pset.add_pset\n>>> {\"product\": {\"cast_type\": \"entity_instance\", \"value\": 4120445, \"Name\": \"Beam.033\"}, \"name\": \"BBIM_Linked_Aggregate\"}\n# ifcopenshell.api: owner.create_owner_history\n>>> {}\n# ifcopenshell.api: pset.assign_pset\n>>> {}\n# ifcopenshell.api: owner.create_owner_history\n>>> {}\n# ifcopenshell.api: pset.edit_pset\n>>> {\"pset\": {\"cast_type\": \"entity_instance\", \"value\": 4120689, \"Name\": \"BBIM_Linked_Aggregate\"}, \"properties\": \"{'Index': 2}\"}\n# ifcopenshell.api: pset.add_pset\n>>> {\"product\": {\"cast_type\": \"entity_instance\", \"value\": 4120503, \"Name\": \"Beam.035\"}, \"name\": \"BBIM_Linked_Aggregate\"}\n# ifcopenshell.api: owner.create_owner_history\n>>> {}\n# ifcopenshell.api: pset.assign_pset\n>>> {}\n# ifcopenshell.api: owner.create_owner_history\n>>> {}\n# ifcopenshell.api: pset.edit_pset\n>>> {\"pset\": {\"cast_type\": \"entity_instance\", \"value\": 4120694, \"Name\": \"BBIM_Linked_Aggregate\"}, \"properties\": \"{'Index': 1}\"}\n# ifcopenshell.api: group.assign_group\n>>> {\"group\": {\"cast_type\": \"entity_instance\", \"value\": 4103768, \"Name\": \"BBIM_Linked_Aggregate\"}, \"products\": [{\"cast_type\": \"entity_instance\", \"value\": 4120597, \"Name\": \"Default_Name_1\"}]}\n# ifcopenshell.api: owner.update_owner_history\n>>> {\"element\": {\"cast_type\": \"entity_instance\", \"value\": 4103770, \"Name\": null}}\n# ifcopenshell.api: pset.add_pset\n>>> {\"product\": {\"cast_type\": \"entity_instance\", \"value\": 4120597, \"Name\": \"Default_Name_1\"}, \"name\": \"BBIM_Linked_Aggregate\"}\n# ifcopenshell.api: owner.create_owner_history\n>>> {}\n# ifcopenshell.api: pset.assign_pset\n>>> {}\n# ifcopenshell.api: owner.create_owner_history\n>>> {}\n# ifcopenshell.api: pset.edit_pset\n>>> {\"pset\": {\"cast_type\": \"entity_instance\", \"value\": 4120699, \"Name\": \"BBIM_Linked_Aggregate\"}, \"properties\": \"{'Index': 0, 'Name': 'Default_Name', 'Aggregate_Index': 3}\"}\n# operator: BIM_OT_override_move_select\n# operator: BIM_OT_refresh_linked_aggregate\nlast_error: Traceback (most recent call last):\n File \"C:\\Users\\Ryan Schultz\\AppData\\Roaming\\Blender Foundation\\Blender\\5.2\\extensions\\.local\\lib\\python3.13\\site-packages\\bonsai\\bim\\ifc.py\", line 569, in execute_ifc_operator\n result = getattr(operator, \"_execute\")(context)\n File \"C:\\Users\\Ryan Schultz\\AppData\\Roaming\\Blender Foundation\\Blender\\5.2\\extensions\\.local\\lib\\python3.13\\site-packages\\bonsai\\bim\\module\\geometry\\operator.py\", line 2062, in _execute\n element_original_data = get_original_data(element)\n File \"C:\\Users\\Ryan Schultz\\AppData\\Roaming\\Blender Foundation\\Blender\\5.2\\extensions\\.local\\lib\\python3.13\\site-packages\\bonsai\\bim\\module\\geometry\\operator.py\", line 1848, in get_original_data\n nested_data = get_original_data(part)\n File \"C:\\Users\\Ryan Schultz\\AppData\\Roaming\\Blender Foundation\\Blender\\5.2\\extensions\\.local\\lib\\python3.13\\site-packages\\bonsai\\bim\\module\\geometry\\operator.py\", line 1821, in get_original_data\n group: int = next(\n ~~~~^\n r.RelatingGroup\n ^^^^^^^^^^^^^^^\n ...\u003c2 lines>...\n if self.group_name in r.RelatingGroup.Name\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n ).id()\n ^\nStopIteration\n\nblend_file_path: D:\\Dropbox\\Gitea_OD\\Entry_Portico\\Open\\Models\\Bonsai\\Entry_Portico.blend\nblend_file_dirty: True\nifc_file_path: Entry_Portico.ifc\nifc_is_dirty: True\nifc: Entry_Portico.ifc\nschema: IFC4\npreprocessor_version: IfcOpenShell 0.0.0\noriginating_system: Bonsai 0.8.6-alpha260923-8ffab9d\n```\n\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-09-24T02:14:49Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9582"}
| 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:b61f529d-24e3-1ab0-d8ef-4ea4d7781d69 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B9AC:A2A16:874A:B68C:6B046A68 |
| html-safe-nonce | f21e8098b7d234a175927ec87b64eea1dbd289b62462b7e654d7e3f00dbda8de |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOUFDOkEyQTE2Ojg3NEE6QjY4Qzo2QjA0NkE2OCIsInZpc2l0b3JfaWQiOiI4ODEzMzI4MzU3Mzc0MzA2MzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2db9d7aa88105a1a2175ada265ab11178b2fc4bb7c0c7f63d621d959cd25e13a |
| hovercard-subject-tag | issue:5562033539 |
| 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/9582/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d2b104928b7482b7df1010dea25e685446de32b8b7f047ab822e22dc1c8cf03e/IfcOpenShell/IfcOpenShell/issues/9582 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d2b104928b7482b7df1010dea25e685446de32b8b7f047ab822e22dc1c8cf03e/IfcOpenShell/IfcOpenShell/issues/9582 |
| og:image:alt | Bug Description bim.refresh_linked_aggregate crashes with StopIteration when a linked aggregate contains a nested IfcElementAssembly that is not itself a linked aggregate. To reproduce: Have severa... |
| 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