Problem:
I’m getting errur during deleting of host
**Oops, we're sorry but something went wrong** PG::ForeignKeyViolation: ERROR: update or delete on table "hosts" violates foreign key constraint "discovery_attribute_sets_host_id_fk" on table "discovery_attribute_sets" DETAIL: Key (id)=(23225) is still referenced from table "discovery_attribute_sets".
There was similar issue in 2015.
This is happening to me as well. I've been testing Foreman Discovery 2.0 on
and off since RC1 was released, so I'm not sure my use case would be
helpful for you. What I see is that I cannot delete the host.
stefanl@foreman:~ $ hammer host delete --id 83
Could not delete the host:
ERROR: update or delete on table "hosts" violates foreign key constraint
"tokens_host_id_fk" on table "tokens"
DETAIL: Key (id)=(83) is still referenced from table "tokens".
stefanl@foreman:~ $
How would I ap…
Expected outcome:
Deleted host
Foreman and Proxy versions:
Proxy - 2.5.4
Foreman - 2.5.3
Foreman and Proxy plugin versions:
Foreman_discovery - 17.0.1
Distribution and version:
Debian Buster
Other relevant data:
Logs fetched by foreman-rake errors:fetch_log request_id=2144156f
2022-01-03T14:56:37 [I|app|2144156f] Started DELETE "/hosts/host_XXX" for xxx.xxx.xxx.xxx at 2022-01-03 14:56:37 +0000
2022-01-03T14:56:37 [I|app|2144156f] Processing by HostsController#destroy as HTML
2022-01-03T14:56:37 [I|app|2144156f] Parameters: {"authenticity_token"=>"M9G9n5AmWk3J22c7Mq448tMofg76JzyRudhU4UT+PM/NUbiJhUokun+MvOWGB0S2AQGYQ1pcGMD3J+eewPcx2g==", "id"=>"host_XXX"}
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on mac 3c:ec:ef:86:e1:36
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on ip
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on type Nic::Managed
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on name
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on host_id 23225
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on subnet_id
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on domain_id
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on attrs {"mtu"=>1500, "duplex"=>"unknown! (255)", "port"=>"Twisted Pair", "auto_negotiation"=>"true"}
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on provider
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on username
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on password [redacted]
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on virtual false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on link false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on identifier eno1
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on tag
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on attached_to
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on managed false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on mode balance-rr
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on attached_devices
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on bond_options
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on primary false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on provision false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on compute_attributes {}
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on ip6
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118177) destroy event on subnet6_id
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on mac 3c:ec:ef:86:e1:37
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on ip
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on type Nic::Managed
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on name
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on host_id 23225
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on subnet_id
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on domain_id
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on attrs {"mtu"=>1500, "duplex"=>"unknown! (255)", "port"=>"Twisted Pair", "auto_negotiation"=>"true"}
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on provider
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on username
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on password [redacted]
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on virtual false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on link false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on identifier eno2d1
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on tag
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on attached_to
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on managed false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on mode balance-rr
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on attached_devices
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on bond_options
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on primary false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on provision false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on compute_attributes {}
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on ip6
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118178) destroy event on subnet6_id
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on mac 3c:fd:fe:9e:ad:3c
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on ip 192.168.43.249
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on type Nic::Managed
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on name host_XXX
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on host_id 23225
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on subnet_id 11
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on domain_id 2
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on attrs {"network"=>"192.168.43.0", "netmask"=>"255.255.255.0", "mtu"=>1500, "speed"=>"40000", "duplex"=>"full", "port"=>"FIBRE", "auto_negotiation"=>"false", "wol"=>false}
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on provider
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on username
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on password [redacted]
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on virtual false
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on link true
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on identifier enp67s0f0
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on tag
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on attached_to
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on managed true
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on mode balance-rr
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on attached_devices
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on bond_options
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on primary true
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on provision true
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on compute_attributes {}
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on ip6
2022-01-03T14:56:38 [I|aud|2144156f] Nic::Managed (118176) destroy event on subnet6_id
2022-01-03T14:56:38 [I|app|2144156f] Delete the TFTP configuration for host_XXX
2022-01-03T14:56:38 [I|app|2144156f] Delete the TFTP configuration for host_XXX
2022-01-03T14:56:39 [I|app|2144156f] Delete the TFTP configuration for host_XXX
2022-01-03T14:56:39 [I|app|2144156f] Delete the TFTP configuration for host_XXX
2022-01-03T14:56:40 [I|app|2144156f] Processed 4 tasks from queue 'Host::Managed Main', completed 4/4
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on mac 3c:fd:fe:9e:ad:3e
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on ip
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on type Nic::Managed
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on name
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on host_id 23225
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on subnet_id
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on domain_id
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on attrs {"mtu"=>1500, "duplex"=>"unknown! (255)", "port"=>"Other", "auto_negotiation"=>"false", "wol"=>false}
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on provider
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on username
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on password [redacted]
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on virtual false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on link false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on identifier enp67s0f1
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on tag
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on attached_to
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on managed false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on mode balance-rr
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on attached_devices
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on bond_options
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on primary false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on provision false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on compute_attributes {}
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on ip6
2022-01-03T14:56:40 [I|aud|2144156f] Nic::Managed (118179) destroy event on subnet6_id
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on mac 3c:ec:ef:86:dd:22
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on ip 10.110.10.222
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on type Nic::BMC
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on name
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on host_id 23225
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on subnet_id
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on domain_id
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on attrs {"enabled"=>true, "ipaddress_source"=>"Static Address", "subnet_mask"=>"255.255.252.0", "gateway"=>"10.110.8.1", "1_ipaddress_source"=>"Static Address", "1_ipaddress"=>"10.110.10.222", "1_subnet_mask"=>"255.255.252.0", "1_macaddress"=>"3c:ec:ef:86:dd:22", "1_gateway"=>"10.110.8.1"}
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on provider IPMI
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on username admin
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on password [redacted]
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on virtual false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on link true
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on identifier ipmi
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on tag
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on attached_to
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on managed false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on mode balance-rr
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on attached_devices
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on bond_options
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on primary false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on provision false
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on compute_attributes {}
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on ip6
2022-01-03T14:56:40 [I|aud|2144156f] Nic::BMC (118180) destroy event on subnet6_id
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on name host_XXX
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on root_pass $5$nJZyF5ry0l091ucI$8cNQLNHdhzd35hRg3XSc0372QdRYcT2HABwfSR5WktD
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on architecture_id 1
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on operatingsystem_id 14
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on environment_id
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on ptable_id 270
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on medium_id 7
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on build false
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on comment Auto-discovered and provisioned via rule 'CHI'
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on disk
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on installed_at 2021-12-30 07:24:58 +0100
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on model_id 40
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on hostgroup_id 6
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on owner_id 3
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on owner_type User
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on enabled true
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on puppet_ca_proxy_id
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on managed true
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on use_image
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on image_file
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on uuid
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on compute_resource_id
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on puppet_proxy_id
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on certname
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on image_id
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on organization_id 2
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on location_id 1
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on otp
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on realm_id
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on compute_profile_id
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on provision_method
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on grub_pass $5$nJZyF5ry0l091ucI$8cNQLNHdhzd35hRg3XSc0372QdRYcT2HABwfSR5WktD
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on discovery_rule_id 17
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on pxe_loader PXELinux BIOS
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on initiated_at 2021-12-30 07:08:24 +0100
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on build_errors
2022-01-03T14:56:40 [I|aud|2144156f] Host::Base (23225) destroy event on registration_facet_attributes {"id"=>60, "host_id"=>23225, "jwt_secret"=>"bMbkWpxIi2xLEnQMuR2CQw=="}
2022-01-03T14:56:40 [W|app|2144156f] PG::ForeignKeyViolation: ERROR: update or delete on table "hosts" violates foreign key constraint "discovery_attribute_sets_host_id_fk" on table "discovery_attribute_sets"
2022-01-03T14:56:40 [I|app|2144156f] Backtrace for 'PG::ForeignKeyViolation: ERROR: update or delete on table "hosts" violates foreign key constraint "discovery_attribute_sets_host_id_fk" on table "discovery_attribute_sets"
2022-01-03T14:56:40 [I|app|2144156f] Rendering common/500.html.erb within layouts/application
2022-01-03T14:56:40 [I|app|2144156f] Rendered common/500.html.erb within layouts/application (Duration: 5.9ms | Allocations: 5655)
2022-01-03T14:56:40 [I|app|2144156f] Rendered layouts/_application_content.html.erb (Duration: 4.0ms | Allocations: 5362)
2022-01-03T14:56:40 [I|app|2144156f] Rendering layouts/base.html.erb
2022-01-03T14:56:40 [I|app|2144156f] Rendered layouts/base.html.erb (Duration: 4.5ms | Allocations: 6625)
2022-01-03T14:56:40 [I|app|2144156f] Completed 500 Internal Server Error in 2433ms (Views: 19.3ms | ActiveRecord: 43.1ms | Allocations: 118957)
Foreman version: 2.5.3
Plugins:
- foreman_dhcp_browser 0.0.8
- foreman_discovery 17.0.1
- foreman_setup 6.0.0
- foreman_statistics 1.1.1
lzap
January 4, 2022, 12:44pm
3
cerberek:
PG::ForeignKeyViolation
Hello, are you performing this as an admin or regular user?
I am thinking somehthing l ike postgresql - Rails Foreign Key violation deleting has_many relationships with dependent destroy - Stack Overflow
As user by API, by it cannot be removed even as admin in GUI.
lzap
January 5, 2022, 9:28am
5
Try this and paste it:
foreman-rake console
> Host::Discovered.all.pluck(:name)
> Host::Discovered.find_by_name("mac522a150e7988").destroy
> Host::Discovered.unscoped.find_by_name("mac522a150e7988").destroy
irb(main):001:0>
irb(main):002:0> Host::Discovered.all.pluck(:name)
=> ["mac-3cecef05cafe", "mac-3cecef05c964", "mac-3cecef6dffd0", "mac-3cecef8b8dac", "mac-3cecef890dbe", "mac-3cecef590990", "mac-3cecef060b4c", "mac-3cecef590b2a", "mac-3cecef05cee2"]
irb(main):003:0> Host::Discovered.find_by_name("mac522a150e7988").destroy
Traceback (most recent call last):
2: from lib/tasks/console.rake:5:in `block in <top (required)>'
1: from (irb):3
NoMethodError (undefined method `destroy' for nil:NilClass)
irb(main):004:0> Host::Discovered.unscoped.find_by_name("mac522a150e7988").destroy
Traceback (most recent call last):
2: from lib/tasks/console.rake:5:in `block in <top (required)>'
1: from (irb):4
NoMethodError (undefined method `destroy' for nil:NilClass)
irb(main):005:0>
lzap
January 6, 2022, 10:40am
7
cerberek:
mac522a150e7988
I thought it would be obvious, but I meant you to replace mac522a150e7988
with an actual discovered host name of yours
Ok, sure my stupidity.
Host which is connected with this id i cannot remove is not anymore between discovered hosts.
When i search by MAC i find it between normal hosts.
lzap
January 7, 2022, 7:15am
9
Here is a question for you: you see the error when deleting a discovered host or a managed host? I kinda assumed it was discovered. Now I understand.
Try this patch, locate the file on your filesystem, patch it, restart foreman, try again and let me know:
theforeman:develop
← lzap:clean-attributes-managed-34232
opened 07:15AM - 07 Jan 22 UTC
Discovered hosts have 1:1 relationship to DiscoveryAttributeSet model, in Rails … the relationship is also specified for the "Host::Discovered" STI class.
During discovered provisioning, application performs a ton of stuff and we do not use SQL transactions due to the fact it breaks callbacks (thus Dynflow/Tasks). When discovery process fails, an incorrect managed host can be sometimes left in the database. The host was already changed to Host::Managed type, but transaction was not processed to the end, when DiscoveryAttributeSet is deleted.
Such a host now still have a related record in the SQL database (with its FOREIGN KEY constraint), but Rails does not see the relationship anymore as the type is not Host::Discovered. Any attempt to delete such host will fail with a foreign key SQL error.
The solution is to simply extend the managed host to also clean up all (now irrelevant) DiscoveryAttributeSet records on delete.
https://community.theforeman.org/t/cannot-remove-host-id-is-still-referenced-from-table-discovery-attribute-sets/26699