Project

General

Profile

Bug #6216

Trying to delete a subnet that is associated with a host group throws foreign key error

Added by Dominic Cleal almost 5 years ago. Updated 11 months ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Rails
Target version:
Difficulty:
Triaged:
Bugzilla link:
Pull request:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1109315
Description of problem:

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Manually create a subnet ('mysubnet', 192.168.100.1, 255.255.255.0)
2. Associate this subnet with a hostgroup
3. Try to delete the subnet

Actual results:
Oops, we're sorry but something went wrong

×
Error

ERROR: update or delete on table "subnets" violates foreign key constraint "hostgroups_subnet_id_fk" on table "hostgroups" DETAIL: Key (id)=(2) is still referenced from table "hostgroups".
If you feel this is an error with Foreman itself, please open a new issue with Foreman ticketing system, You would probably need to attach the Full trace and relevant log entries.

Expected results:
A handled exception and perhaps a UI block on trying to delete a subnet that is already associated.

Additional info:

Associated revisions

Revision e0d618ef (diff)
Added by Joseph Magen almost 5 years ago

fixes #6216, #4416 - avoid foreign key errors when deleting some objects in use

Revision 3d5d2c5c (diff)
Added by Joseph Magen almost 5 years ago

fixes #6216, #4416 - avoid foreign key errors when deleting some objects in use

(cherry picked from commit e0d618efa6a8c02b46000bfcb9ded5eb672a6e13)

History

#1 Updated by Dominic Cleal almost 5 years ago

  • Category set to Rails

Missing an EnsureNotUsedBy.new(:hostgroups) on the subnet. Worth double checking all other foreign keys have similar before_destroy hooks for friendly errors.

#2 Updated by Joseph Magen almost 5 years ago

  • Status changed from New to Assigned
  • Assignee set to Joseph Magen
  • Target version set to 1.8.1

#3 Updated by Joseph Magen almost 5 years ago

  • Status changed from Assigned to Ready For Testing

https://github.com/theforeman/foreman/pull/1513

I suggest to have Ori review other places foreign keys are missing before_destroy EnsureNotUsedBy.new

#4 Updated by Dominic Cleal almost 5 years ago

  • Legacy Backlogs Release (now unused) set to 18

#5 Updated by Joseph Magen almost 5 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF