Project

General

Profile

Actions

Bug #39280

closed

Organization delete fails with HasManyThroughNestedAssociationsAreReadonly on environment destroy

Added by Zach Huntington-Meath 2 months ago. Updated 2 months ago.

Status:
Closed
Priority:
Normal
Category:
Organizations and Locations
Target version:
Difficulty:
Triaged:
Yes
Fixed in Releases:
Found in Releases:

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.

Actions #1

Updated by Zach Huntington-Meath 2 months ago

  • Red Hat JIRA set to SAT-44830
Actions #2

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
Actions #3

Updated by The Foreman Bot 2 months ago

  • Fixed in Releases Katello 4.21.0 added
Actions #4

Updated by Zach Huntington-Meath 2 months ago

  • Status changed from Ready For Testing to Closed
Actions #5

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
Actions

Also available in: Atom PDF