Title: copy_class shares the original's annotations with the duplicate, assigning them to two products (cause behind #4014) · Issue #9049 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: copy_class shares the original's annotations with the duplicate, assigning them to two products (cause behind #4014) · Issue #9049 · IfcOpenShell/IfcOpenShell
X Title: copy_class shares the original's annotations with the duplicate, assigning them to two products (cause behind #4014) · Issue #9049 · IfcOpenShell/IfcOpenShell
Description: Bug Description Duplicating a product that has annotations assigned to it (Shift+D in Bonsai, or ifcopenshell.api.root.copy_class directly) does not give the copy its own annotations, and does not leave the copy without annotations eithe...
Open Graph Description: Bug Description Duplicating a product that has annotations assigned to it (Shift+D in Bonsai, or ifcopenshell.api.root.copy_class directly) does not give the copy its own annotations, and does not ...
X Description: Bug Description Duplicating a product that has annotations assigned to it (Shift+D in Bonsai, or ifcopenshell.api.root.copy_class directly) does not give the copy its own annotations, and does not ...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9049
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"copy_class shares the original's annotations with the duplicate, assigning them to two products (cause behind #4014)","articleBody":"### Bug Description\n\nDuplicating a product that has annotations assigned to it (Shift+D in Bonsai, or `ifcopenshell.api.root.copy_class` directly) does not give the copy its own annotations, and does not leave the copy without annotations either. It clones the `IfcRelAssignsToProduct` relationship, points the clone at the new product, and keeps the **original's annotations** in `RelatedObjects`. Both products then claim the same annotation entities, so every annotation involved ends up assigned to two products.\n\nThis appears to be the missing cause behind #4014. PR #8373 says as much in its own scope note: *\"this does not address how annotations accumulate multiple products in the first place (still under investigation via the diagnostic warning).\"* This is that path.\n\n**Minimal reproduction** (no Blender required):\n\n```python\nimport ifcopenshell, ifcopenshell.api.root, ifcopenshell.guid\n\nf = ifcopenshell.file(schema=\"IFC4\")\nwall = ifcopenshell.api.root.create_entity(f, ifc_class=\"IfcWall\")\nannotation = ifcopenshell.api.root.create_entity(f, ifc_class=\"IfcAnnotation\")\nf.create_entity(\"IfcRelAssignsToProduct\", GlobalId=ifcopenshell.guid.new(),\n RelatedObjects=[annotation], RelatingProduct=wall)\n\ncopy = ifcopenshell.api.root.copy_class(f, product=wall)\n\nrels = [r for r in annotation.HasAssignments if r.is_a(\"IfcRelAssignsToProduct\")]\nprint(len(rels), [r.RelatingProduct.id() for r in rels])\n```\n\n```\nbefore: annotation assigned to 1 product(s)\nafter copy_class: annotation assigned to 2 product(s): [1, 4] # original wall #1, copy #4\n```\n\n**Root cause.** In `src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py`, `IfcRelAssignsToProduct` matches none of the special cases in `copy_indirect_attributes`, so it falls through to the generic `else` branch:\n\n```python\nelse:\n for i, value in enumerate(inverse):\n if value == from_element:\n new_inverse = ifcopenshell.util.element.copy(self.file, inverse)\n new_inverse[i] = to_element\n```\n\n`value == from_element` matches at `RelatingProduct`, so the whole relationship is copied and only that one attribute is swapped. `RelatedObjects` — the original's annotations — is carried over untouched.\n\n**Impact in a real project.** In a production model of mine, 60 of 808 annotations are assigned to more than one product, across 22 rel-sets that are exact clones (same `RelatedObjects`, different `RelatingProduct`). One `IfcSpace` was duplicated twice, so a single annotation is now assigned to three spaces:\n\n```\nannotation #3542995\n via rel #3543012 -> #3540997 IfcSpace 06XX6WklnFdeYNmzrdhn4i\n via rel #3550684 -> #3550678 IfcSpace 3LKyBBG0LDLwxBGxvi_Qyn\n via rel #3552280 -> #3552274 IfcSpace 2E30n7LafENhO3LEp8hJYt\n```\n\nThe practical consequence is that `tool.Drawing.get_assigned_product` returns whichever rel happens to come first, so an annotation can silently label the wrong element. `tool.Drawing.get_assigned_product_workaround` exists to paper over exactly this and prints the multi-product warning pointing at #4014.\n\n**Relationship to existing work.**\n\n- #6621 / PR #8032 fix the case where the *annotation* is duplicated (alone, or together with its product). I reimplemented `fix_assigns_to_product_after_duplication` from that PR verbatim and ran it against both scenarios: it fixes duplicating product + annotation together, but the guard `if not rel.is_a(\"IfcRelAssignsToProduct\") or new_elem not in rel.RelatedObjects: continue` skips this case entirely, because here the new element is the `RelatingProduct`, not a related object. The two fixes are complementary, not competing.\n- #8373 / #8374 clean up annotations that already have multiple products; they don't prevent them being created.\n\n**Suggested fix.** Skip the relationship when the element being copied is the `RelatingProduct`, the same way `IfcRelAggregates` and `IfcRelContainedInSpatialStructure` are already skipped when the copied element is on the relating side. The duplicate then simply starts with no annotations.\n\nThe opposite direction must keep working: when an *annotation* is copied it takes the list branch, which appends the copy to the same relationship, and that behaviour is what the copy-annotation-to-drawing feature relies on.\n\nNote this is a behaviour change for every `copy_class` caller, not just Bonsai's duplicate path: a duplicated product will no longer inherit assignments made *to* it through `IfcRelAssignsToProduct`, which can include objects other than annotations.\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-07-29T14:26:15Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9049"}
| 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:0e14310b-1e44-4d71-6605-4402101d0ccc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B748:3C835:5BA3D5:80A17C:6B047566 |
| html-safe-nonce | 9964c0393e40bd00bde862a1f547da66405b7095c97a2103e84326917e922ae0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzQ4OjNDODM1OjVCQTNENTo4MEExN0M6NkIwNDc1NjYiLCJ2aXNpdG9yX2lkIjoiMTYyMjY0MjQwNDMyMDYzODMxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 375c5e73e704de035513db230a9bbfab7a7ca02eba6160a753cf1fc471cfa286 |
| hovercard-subject-tag | issue:5010353641 |
| 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/9049/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ddbf02949c1d24d820ea7a067b34f168b6c0c5658bea099f5e092df770cbc7c/IfcOpenShell/IfcOpenShell/issues/9049 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ddbf02949c1d24d820ea7a067b34f168b6c0c5658bea099f5e092df770cbc7c/IfcOpenShell/IfcOpenShell/issues/9049 |
| og:image:alt | Bug Description Duplicating a product that has annotations assigned to it (Shift+D in Bonsai, or ifcopenshell.api.root.copy_class directly) does not give the copy its own annotations, and does not ... |
| 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 | 9c099f1b85def81ca352464c276510dfef32deaf3c305404e65b8d270284a58b |
| 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 | cf73f57448d52b3a7b619195e182b33d3b3454ca |
| 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