Bug #39280
closedOrganization delete fails with HasManyThroughNestedAssociationsAreReadonly on environment destroy
Description
When deleting an organization, Environment::Destroy#plan calls delete_host_and_hostgroup_associations, which attempts to call environment.hostgroups.delete_all. This raises ActiveRecord::HasManyThroughNestedAssociationsAreReadonly because KTEnvironment#hostgroups is a doubly-nested has_many :through (KTEnvironment → content_view_environments → hostgroup_content_facets → hostgroups).
Rails does not permit write operations on such associations.
Fix: move the cleanup logic into KTEnvironment#delete_host_and_hostgroup_associations, operating directly on the intermediate join model (Hostgroup::ContentFacet) rather than the nested association. Use destroy_all to properly cascade dependent associations and preserve audit records, consistent with the equivalent method in ContentView::Remove.
Updated by The Foreman Bot 2 months ago
- Status changed from New to Ready For Testing
- Assignee set to Zach Huntington-Meath
- Pull request https://github.com/Katello/katello/pull/11722 added
Updated by Zach Huntington-Meath 2 months ago
- Status changed from Ready For Testing to Closed
Applied in changeset katello|86d88810460fec45118a0348ad3ca36fa4738947.
Updated by Vladimir Sedmik 2 months ago
- Category set to Organizations and Locations
- Target version set to Katello 4.21.0
- Triaged changed from No to Yes