Title: ifcpatch MergeDuplicateTypes: default merges distinct untagged types (data loss) and can crash on cross-class merges · Issue #8609 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: ifcpatch MergeDuplicateTypes: default merges distinct untagged types (data loss) and can crash on cross-class merges · Issue #8609 · IfcOpenShell/IfcOpenShell
X Title: ifcpatch MergeDuplicateTypes: default merges distinct untagged types (data loss) and can crash on cross-class merges · Issue #8609 · IfcOpenShell/IfcOpenShell
Description: Summary The ifcpatch recipe MergeDuplicateTypes can silently destroy distinct element types (and, as a knock-on effect, break Bonsai array modifiers that reference them). There are two related problems in the recipe: should_merge_null=Tr...
Open Graph Description: Summary The ifcpatch recipe MergeDuplicateTypes can silently destroy distinct element types (and, as a knock-on effect, break Bonsai array modifiers that reference them). There are two related prob...
X Description: Summary The ifcpatch recipe MergeDuplicateTypes can silently destroy distinct element types (and, as a knock-on effect, break Bonsai array modifiers that reference them). There are two related prob...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/8609
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ifcpatch MergeDuplicateTypes: default merges distinct untagged types (data loss) and can crash on cross-class merges","articleBody":"## Summary\n\nThe `ifcpatch` recipe **`MergeDuplicateTypes`** can silently destroy distinct element types (and, as a knock-on effect, break Bonsai array modifiers that reference them). There are two related problems in the recipe:\n\n1. **`should_merge_null=True` is the default**, which merges *every* type that has an empty merge attribute into a single type — even when those types are clearly not duplicates.\n2. **Types are grouped by the attribute value only, ignoring their IFC class**, so two unrelated types that happen to share a value can be merged, which then raises a `TypeError` from `assign_type` (or, worse, silently mis-types occurrences).\n\nRecipe: [`src/ifcpatch/ifcpatch/recipes/MergeDuplicateTypes.py`](https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcpatch/ifcpatch/recipes/MergeDuplicateTypes.py)\n\n## Problem 1 — `should_merge_null=True` destroys distinct untagged types\n\nThe default groups types by `Tag`. With `should_merge_null=True`, all types with an empty `Tag` are treated as duplicates of one another and collapsed into a single type. But an empty attribute is an *absence of evidence*, not proof of duplication.\n\nOn a Bonsai-authored (or mixed) model this is destructive. For example a masonry assembly built with array modifiers had three distinct, differently-named types that all happened to lack a `Tag`:\n\n- `IfcBuildingElementProxyType` \"Wire Ladder\"\n- `IfcBuildingElementProxyType` \"CMU Core\"\n- `IfcBuildingElementProxyType` \"Mortar Joint\"\n\nRunning the default patch collapsed all three into one and removed the other two. Because these types were referenced as **array children** in `BBIM_Array` psets, re-opening the patched file in Bonsai produced:\n\n```\nsetup_arrays: array parent 3QecqJiErB$9TeAgOjclzW references missing child GUID '2N9VxgdQL2eO0eoCEe8Bi_'.\nsetup_arrays: array parent 0QwQTUhPr6EAqfEjNat8se references missing child GUID '0d1KDqYRrCE9_7zIFzbh7M'.\nsetup_arrays: array parent 3iGRJZfy51iAd8K3LgiYDq references missing child GUID '3FI_7o4Dz1keW3geVnqXHX'.\n```\n\n(\"Arrays With Missing Children\" warning in the Project panel.)\n\nGenuine Revit duplicates — the recipe's intended target — always carry a populated `Tag`, so merging untagged types buys nothing for that workflow while risking data loss elsewhere.\n\n### Minimal repro\n\n```python\nimport ifcopenshell, ifcopenshell.api.root, ifcpatch\n\nf = ifcopenshell.file(schema=\"IFC4\")\nfor name in (\"Wire Ladder\", \"CMU Core\", \"Mortar Joint\"):\n ifcopenshell.api.root.create_entity(f, ifc_class=\"IfcBuildingElementProxyType\", name=name)\n # Tag left as None\n\nout = ifcpatch.execute({\"file\": f, \"recipe\": \"MergeDuplicateTypes\", \"arguments\": []})\nprint(len(out.by_type(\"IfcBuildingElementProxyType\"))) # -> 1 (expected 3)\n```\n\n## Problem 2 — cross-class merge raises `TypeError`\n\nBecause the grouping key ignores the IFC class, two unrelated types with the same (or both-empty) attribute value can be merged. When the \"keeper\" type cannot type the other type's occurrences, `assign_type` raises. Observed on a Revit export:\n\n```\nTypeError: IfcTypeProduct cannot type IfcBeam in schema IFC4 (allowed occurrence classes: IfcAnnotation)\n```\n\n(Bonsai uses `IfcTypeProduct` for annotation types; it collided with a beam type on an empty `Tag`.)\n\n### Minimal repro\n\n```python\nimport ifcopenshell, ifcopenshell.api.root, ifcopenshell.api.type, ifcpatch\n\nf = ifcopenshell.file(schema=\"IFC4\")\nat = ifcopenshell.api.root.create_entity(f, ifc_class=\"IfcTypeProduct\")\na = ifcopenshell.api.root.create_entity(f, ifc_class=\"IfcAnnotation\")\nifcopenshell.api.type.assign_type(f, related_objects=[a], relating_type=at, should_map_representations=False)\nbt = ifcopenshell.api.root.create_entity(f, ifc_class=\"IfcBeamType\")\nb = ifcopenshell.api.root.create_entity(f, ifc_class=\"IfcBeam\")\nifcopenshell.api.type.assign_type(f, related_objects=[b], relating_type=bt, should_map_representations=False)\n\nifcpatch.execute({\"file\": f, \"recipe\": \"MergeDuplicateTypes\", \"arguments\": [\"Tag\", True]}) # -> TypeError\n```\n\n## Proposed fix\n\n1. Include the IFC class in the grouping key so only same-class types are ever merged.\n2. Change the default to `should_merge_null=False`, so untagged types are kept separate unless the caller explicitly opts in via `[\"Tag\", True]`.\n\nBoth changes are small and localized to the recipe. Happy to open a PR with these plus regression tests covering: same-class populated-attribute duplicates still merge; distinct null-attribute types are preserved by default; cross-class types are never merged (no `TypeError`); and the explicit `should_merge_null` toggle still works.\n\n### Remaining edge case (not addressed by the above)\n\nEven with those fixes, any type removal in this recipe can orphan a `BBIM_Array` \"children\" reference if a genuinely-duplicate type is also an array child. A more complete fix would make the recipe array-aware (repoint or clean up `BBIM_Array` child GUIDs when a referenced type is merged away). Noting it here for completeness.\n\n## Environment\n\n- IfcOpenShell / Bonsai `v0.8.0` branch\n- Blender 4.5, Windows 10\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-07-15T21:12:44Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/8609"}
| 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:1e2732cd-06b2-9819-e42e-d1123e655355 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7CC:2505E9:361F:49B6:6B04AD1F |
| html-safe-nonce | a6c5c99138b290ee34c08ba8583cead3c34a69dcb6bf64b61c8329fbd97bf0a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0NDOjI1MDVFOTozNjFGOjQ5QjY6NkIwNEFEMUYiLCJ2aXNpdG9yX2lkIjoiNDU1Nzg3NzE2MjQwNTA0NzU4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cc1caca6bc1522341bb8960647813382f32c323f3f423db8f893e38332cf600b |
| hovercard-subject-tag | issue:4896373890 |
| 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/8609/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4acb846bdc7bc027ed6949976652bb24e92b22d5d010cb1b68f0654687282962/IfcOpenShell/IfcOpenShell/issues/8609 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4acb846bdc7bc027ed6949976652bb24e92b22d5d010cb1b68f0654687282962/IfcOpenShell/IfcOpenShell/issues/8609 |
| og:image:alt | Summary The ifcpatch recipe MergeDuplicateTypes can silently destroy distinct element types (and, as a knock-on effect, break Bonsai array modifiers that reference them). There are two related prob... |
| 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 | f1d110ea058a0915c1d8aa3fc2069fa15801e128f591e5762525abe77490ecb1 |
| 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 | ffa22a65e4c46d376940fe34b05e6a7e9c7fdb9b |
| 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