Title: Adding a typed annotation crashes: `TypeError: IfcTypeProduct cannot type IfcAnnotation` · Issue #8210 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Adding a typed annotation crashes: `TypeError: IfcTypeProduct cannot type IfcAnnotation` · Issue #8210 · IfcOpenShell/IfcOpenShell
X Title: Adding a typed annotation crashes: `TypeError: IfcTypeProduct cannot type IfcAnnotation` · Issue #8210 · IfcOpenShell/IfcOpenShell
Description: Bug Description Describe the bug Adding an annotation that has an associated annotation type (e.g. a TEXT annotation with a custom type/symbol) crashes with: TypeError: IfcTypeProduct cannot type IfcAnnotation in schema IFC4 (allowed occ...
Open Graph Description: Bug Description Describe the bug Adding an annotation that has an associated annotation type (e.g. a TEXT annotation with a custom type/symbol) crashes with: TypeError: IfcTypeProduct cannot type I...
X Description: Bug Description Describe the bug Adding an annotation that has an associated annotation type (e.g. a TEXT annotation with a custom type/symbol) crashes with: TypeError: IfcTypeProduct cannot type I...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/8210
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Adding a typed annotation crashes: `TypeError: IfcTypeProduct cannot type IfcAnnotation`","articleBody":"### Bug Description\n\n\n\n### Describe the bug\n\nAdding an annotation that has an associated annotation type (e.g. a TEXT annotation with a custom type/symbol) crashes with:\n\n```\nTypeError: IfcTypeProduct cannot type IfcAnnotation in schema IFC4 (allowed occurrence classes: \u003cnone>)\n\n```\n\nThis is a regression — typed annotations worked before the commit identified below.\n\n### To Reproduce\n\n1. Create or select a drawing.\n2. Create an annotation type (TEXT) — Bonsai stores it as an `IfcTypeProduct` with `ApplicableOccurrence = \"IfcAnnotation/TEXT\"`.\n3. Add a TEXT annotation that references that type (e.g. via the annotation hotkey with a relating type selected).\n4. Crash on assignment of the type to the new annotation.\n\n### Expected behavior\n\nThe annotation is created and the annotation type is assigned to it, as before.\n\n### Root cause\n\nThe crash is raised by the type/occurrence class-pairing validation added in:\n\n> **`10ee5aef4f` — \"Bonsai: refuse class-mismatched type assignment\"** (2026-06-24)\n\nin `ifcopenshell/api/type/assign_type.py`:\n\n```python\nallowed_occurrences = ifcopenshell.util.type.get_applicable_entities(\n relating_type.is_a(), schema=self.file.schema\n)\nmismatched_classes = sorted({o.is_a() for o in related_objects if o.is_a() not in allowed_occurrences})\nif mismatched_classes:\n raise TypeError(...)\n\n```\n\nThe validation derives the allowed occurrence classes solely from the buildingSMART implementer-agreement map (`ifcopenshell.util.type.get_applicable_entities`). That map has **no entry for the abstract `IfcTypeProduct`**:\n\n```python\n>>> ifcopenshell.util.type.get_applicable_entities(\"IfcTypeProduct\", \"IFC4\")\n[]\n\n```\n\nHowever, Bonsai's drawing module deliberately uses `IfcTypeProduct` for annotation types, because IFC4 has no `IfcAnnotationType`. The intended occurrence class is recorded in the type's `ApplicableOccurrence` attribute (e.g. `\"IfcAnnotation/TEXT\"`), set in `bim/module/drawing/operator.py`, and Bonsai already reads it back in `tool.Drawing.is_annotation_object_type`.\n\nBecause the new validation ignores `ApplicableOccurrence`, it sees zero allowed occurrences for `IfcTypeProduct` and rejects every annotation type assignment.\n\n### Traceback\n\n```\nFile \".../bonsai/core/drawing.py\", line 556, in add_annotation\n drawing_tool.run_type_assign_type(element=element, relating_type=relating_type)\nFile \".../bonsai/tool/drawing.py\", line 1315, in run_type_assign_type\n return bonsai.core.type.assign_type(...)\nFile \".../bonsai/core/type.py\", line 37, in assign_type\n ifc.run(\"type.assign_type\", related_objects=[element], relating_type=type)\n...\nFile \".../ifcopenshell/api/type/assign_type.py\", line 201, in execute\n raise TypeError(\nTypeError: IfcTypeProduct cannot type IfcAnnotation in schema IFC4 (allowed occurrence classes: \u003cnone>)\n\n```\n\n### Environment\n\n- OS: Windows 10 (10.0.19045)\n- Blender: 4.5.7 LTS\n- Bonsai: 0.8.6-alpha260625, commit `a0432bb`, branch `build-0.8.6-alpha2606251135`\n- Schema: IFC4\n\n### Suggested fix\n\nHave the validation honor `IfcTypeProduct.ApplicableOccurrence` — the schema-defined attribute meant exactly for declaring the applicable occurrence class — in addition to the implementer-agreement map. To avoid trusting free-form text, only add the leading class token when it resolves to a real entity in the schema. This preserves the intent of `10ee5aef4f` (genuine mismatches like `IfcWallType` → `IfcWindow` are still rejected) while restoring typed annotations.\n\n\n\n### Attachments\n\n_No response_\n\n### Debug and Error Output\n\n```true\n\n```","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-06-26T21:44:19Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/8210"}
| 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:c1af8e76-beac-2144-a348-20ff4d39f278 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 887E:5F1E9:1E4878:28A31C:6B04832E |
| html-safe-nonce | 69dbf49960eb8fa52fa2a8be37665a4fea981eebc35849c96abb51891d0e8234 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODdFOjVGMUU5OjFFNDg3ODoyOEEzMUM6NkIwNDgzMkUiLCJ2aXNpdG9yX2lkIjoiMTEwMjA0NTQ4NDE4MjQzODcwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | db681820eeb3a796a3be03e052ab9a7d09a7eb9cdc329773d4dc68d35c4ee7f9 |
| hovercard-subject-tag | issue:4755316102 |
| 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/8210/issue_layout |
| twitter:image | https://opengraph.githubassets.com/442312020fed09013e92adea20a021fc8610761a030f3f31d57f6f7c85ae7efa/IfcOpenShell/IfcOpenShell/issues/8210 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/442312020fed09013e92adea20a021fc8610761a030f3f31d57f6f7c85ae7efa/IfcOpenShell/IfcOpenShell/issues/8210 |
| og:image:alt | Bug Description Describe the bug Adding an annotation that has an associated annotation type (e.g. a TEXT annotation with a custom type/symbol) crashes with: TypeError: IfcTypeProduct cannot type I... |
| 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