Title: ifcopenshell.api: five removal functions write empty aggregates that the schema forbids · Issue #9165 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: ifcopenshell.api: five removal functions write empty aggregates that the schema forbids · Issue #9165 · IfcOpenShell/IfcOpenShell
X Title: ifcopenshell.api: five removal functions write empty aggregates that the schema forbids · Issue #9165 · IfcOpenShell/IfcOpenShell
Description: Summary Five ifcopenshell.api removal functions write schema-invalid IFC when they remove the last member of an aggregate whose schema minimum is 1. Each was confirmed by running the function and validating the result, not by reading cod...
Open Graph Description: Summary Five ifcopenshell.api removal functions write schema-invalid IFC when they remove the last member of an aggregate whose schema minimum is 1. Each was confirmed by running the function and v...
X Description: Summary Five ifcopenshell.api removal functions write schema-invalid IFC when they remove the last member of an aggregate whose schema minimum is 1. Each was confirmed by running the function and v...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9165
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ifcopenshell.api: five removal functions write empty aggregates that the schema forbids","articleBody":"## Summary\n\nFive `ifcopenshell.api` removal functions write **schema-invalid IFC** when they remove the last member of an aggregate whose schema minimum is 1. Each was confirmed by running the function and validating the result, not by reading code.\n\nThey are grouped here rather than filed separately because **each one needs the same kind of decision**, and in two cases the obvious fix makes things worse. No patch is proposed, because guessing here would trade one invalid state for another.\n\nThis matters more than a normal validation nit: Bonsai authors IFC natively, so the `.ifc` is the live database. These corrupt the user's model at the moment they click a button, with no error shown.\n\n## The five\n\n| Function | Leaves | Schema requires |\n|---|---|---|\n| `material.remove_layer` | `IfcMaterialLayerSet.MaterialLayers = ()` | `list [1:?]` |\n| `material.remove_profile` | `IfcMaterialProfileSet.MaterialProfiles = ()` | `list [1:?]` |\n| `material.remove_list_item` | `IfcMaterialList.Materials = ()` | `list [1:?]` |\n| `grid.remove_grid_axis` | `IfcGrid.UAxes` / `VAxes = ()` | `list [1:?]` |\n| `style.remove_surface_style` | `IfcSurfaceStyle.Styles = ()` | `set [1:5]` |\n\n## Why the obvious fix is wrong for the material cases\n\nThe natural fix is to cascade-delete the owning set when it empties, mirroring the precedent in `layer/unassign_layer.py`. **That was implemented and rejected**, because it produces a worse invalid state:\n\n```\nIfcRelAssociatesMaterial.RelatingMaterial = None -> \"Attribute not optional\"\n```\n\nReproduced for both `remove_layer` and `remove_list_item`. So a correct fix must also clean up the material-assignment relationship, which means silently un-materialising every product that used that set. That is a behavioural decision about what the API should do to the user's model, not a bug fix.\n\n**Question for maintainers:** when the last layer is removed from a material set that products are still using, should the API (a) refuse and raise, (b) delete the set and the assignment relationship, un-materialising those products, or (c) leave the set with a single placeholder layer?\n\n## Why `grid.remove_grid_axis` is worse\n\nThe only schema-legal outcome of removing the last U or V axis is **deleting the entire `IfcGrid`**. Auto-deleting a whole product as a side effect of removing one axis is a large and surprising behaviour, so it should be a deliberate decision rather than something slipped into a bug fix.\n\n**Question:** should removing the last axis raise, or delete the grid?\n\n## Why `style.remove_surface_style` is blocked differently\n\nHere two functions disagree about ownership. `style/remove_style.py` loops `for style_ in style.Styles: remove_surface_style(...)` and then unconditionally calls `file.remove(style)` itself. If `remove_surface_style` starts deleting the now-empty parent, `remove_style` double-removes a dangling handle. `remove_surface_style` is also used standalone elsewhere with no such cleanup.\n\n**Question:** which of the two owns deleting the emptied `IfcSurfaceStyle`?\n\n## How these were found, and what is NOT broken\n\nEvery `remove_*` and `unassign_*` function under `ifcopenshell.api` was enumerated and checked against schema cardinality:\n\n- 89 functions enumerated, 84 audited (5 excluded as already in open PRs)\n- 64 distinct entity types cross-referenced against schema cardinality\n- 9 last-member cases constructed and validated\n- **5 genuine defects, listed above**\n\n**The large majority of the 84 were already correctly guarded**, via `len(x) == 1` checks, singleton comparisons, or an existing fallback to `None` or delete-the-relationship. This class is concentrated, not endemic.\n\nConfirmed benign by direct test rather than assumption: `material.remove_constituent`, `sequence.remove_work_time` and `sequence.remove_time_period` auto-null correctly; `pset_template.remove_prop_template` no-ops safely on the last template.\n\nThree aggregates are unreachable through the current API because no `add_*` populates them: `IfcStructuralAnalysisModel.LoadedBy`, `IfcStructuralLoadConfiguration.Values`, `IfcMaterialClassificationRelationship.MaterialClassifications`.\n\n## Related, already fixed\n\nThe same defect class in `cost.unassign_cost_item_quantity`, `group.update_group_products` and `resource.remove_resource` is fixed in #9161, and in `cost.remove_cost_item_quantity` in #9164. Those had unambiguous fixes with existing precedent; these five do not.\n\nHappy to implement whichever answers you prefer, with tests.\n\nGenerated with the assistance of an AI coding tool.\n","author":{"url":"https://github.com/petruconduraru","@type":"Person","name":"petruconduraru"},"datePublished":"2026-07-30T20:33:20Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9165"}
| 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:199528c9-62dc-67f4-3683-305bc377796f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C74E:4818E:27A43D:3682B1:6B046940 |
| html-safe-nonce | 8103c46d70a11d86e9fed1b6a64815b77429663b3f5d677e5fe78ef32bdde749 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzRFOjQ4MThFOjI3QTQzRDozNjgyQjE6NkIwNDY5NDAiLCJ2aXNpdG9yX2lkIjoiMjczMDMxNDIzODAzMDgwMTIxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 67ce559e0e2173390c5c0570e6b5785d361092fe3196a644ccc253f6bab0a520 |
| hovercard-subject-tag | issue:5023762478 |
| 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/9165/issue_layout |
| twitter:image | https://opengraph.githubassets.com/49f10fc3a39731e8e7c2ca2ea7e37392e769782bbd6abac592b2397538762a8d/IfcOpenShell/IfcOpenShell/issues/9165 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/49f10fc3a39731e8e7c2ca2ea7e37392e769782bbd6abac592b2397538762a8d/IfcOpenShell/IfcOpenShell/issues/9165 |
| og:image:alt | Summary Five ifcopenshell.api removal functions write schema-invalid IFC when they remove the last member of an aggregate whose schema minimum is 1. Each was confirmed by running the function and v... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | petruconduraru |
| 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