Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload stale source_tenant after destroying self (rails 5.2) #19367

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/manageiq/providers/cloud_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def self.display_name(number = 1)

def destroy_mapped_tenants
if source_tenant
# We just destroyed ourself, reload the source_tenant association
source_tenant.reload
source_tenant.all_subtenants.destroy_all
source_tenant.all_subprojects.destroy_all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

darn - feels like this should all be destroyed in tenant itself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed

source_tenant.destroy
kbrock marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def create_tenant_group

def ensure_can_be_destroyed
errors.add(:base, _("A tenant with groups associated cannot be deleted.")) if miq_groups.non_tenant_groups.exists?
errors.add(:base, _("A tenant created by tenant mapping cannot be deleted.")) if source
errors.add(:base, _("A tenant created by tenant mapping cannot be deleted.")) if source&.persisted?
throw :abort unless errors[:base].empty?
end

Expand Down