Red Hat Bugzilla – Bug 1197477
ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens"
Last modified: 2017-02-23 15:24:55 EST
Description of problem: FK violation when trying to delete a discovered host after provision Version-Release number of selected component (if applicable): discovery 2.0 How reproducible: When provision on a discovered host fails there is a token created that is not deleted. Provisioning the same host again will create a new token for that host. Trying to delete the host after provision deletes only the second token, to avoid leaving an orphaned token the delete fails with a FK violation error Steps to Reproduce: 1. discover a host 2. try to provision that host but don't put anything in the host edit form 3. save 4. fill in correct values to provision the host 5. save 6. try to delete the new managed host that was created Actual results: The error in the title Expected results: host is deleted Additional info:
Since this issue was entered in Red Hat Bugzilla, the release flag has been set to ? to ensure that it is properly evaluated for this release.
Moving to POST since upstream bug http://projects.theforeman.org/issues/9597 has been closed ------------- Ori Rabin Applied in changeset commit:foreman_discovery|bc01733928b6babaf0feefbbce326169ae588b08.
Verified with: sat6.1 beta snap6 compose2 (Satellite-6.1.0-RHEL-6-20150311.1). I followed all the steps in bz description, but could n't reproduce the reported the issue. Moving to verified.
I can reproduce same issue but in a bit different scenario: I re-discovered same host which was discovered earlier and this throws following error: -- 2015-03-16 12:09:21 [I] Processing by Api::V2::DiscoveredHostsController#facts as JSON 2015-03-16 12:09:21 [I] Parameters: {"facts"=>"[FILTERED]", "apiv"=>"v2", "discovered_host"=>{"facts"=>"[FILTERED]"}} 2015-03-16 12:09:21 [I] Import facts for 'mac525400a5bc0e' completed. Added: 0, Updated: 4, Deleted 0 facts 2015-03-16 12:09:22 [I] Match found for host mac525400a5bc0e (11) rule rule1 (1) 2015-03-16 12:09:22 [I] ForemanDiscovery: Rebooting mac525400a5bc0e 2015-03-16 12:09:22 [I] ForemanDiscovery: reboot result: successful 2015-03-16 12:09:22 [W] Rolling back due to a problem: [] 2015-03-16 12:09:22 [E] ActiveRecord::Rollback 2015-03-16 12:09:22 [E] Unprocessable entity Host::Discovered (id: 11): Name has already been taken --- but when I tried to delete it from webUI, I got following error: -- 2015-03-16 12:08:34 [I] Processing by DiscoveredHostsController#destroy as HTML 2015-03-16 12:08:34 [I] Parameters: {"authenticity_token"=>"5cZuH5IlnPJKmdqlaE3t47OH4JcWmXbzeenN6It/fjo=", "id"=>"mac525400a5bc0e"} 2015-03-16 12:08:34 [W] Operation FAILED: ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(11) is still referenced from table "tokens". 2015-03-16 12:08:34 [I] Rendered common/500.html.erb within layouts/application (6.0ms) 2015-03-16 12:08:34 [I] Rendered layouts/base.html.erb (1.4ms) 2015-03-16 12:08:34 [I] Completed 500 Internal Server Error in 84ms (Views: 11.4ms | ActiveRecord: 16.1ms) ---
Reproducible with sat6.1 beta snap6 compose2 (Satellite-6.1.0-RHEL-6-20150311.1).
Created attachment 1002240 [details] UI throwing error in deleting a discovered host
Oh, thanks. Re-test please.
I reproduced similar issue on Sat6.1 beta snap7 compose3..
I'll test this again with snap8 and will update here.. thanks
Guys, this issue is reproducible in snap8 (Satellite-6.1.0-RHEL-7-20150324.0). -- 2015-03-31 18:36:37 [I] Processing by HostsController#destroy as HTML 2015-03-31 18:36:37 [I] Parameters: {"authenticity_token"=>"x/5flBIFQMT2FhwJCPof+IJ+JZlEPZF8cnJQo4Cn0tw=", "id"=>"mac525400492906.lab.eng.pnq.redhat.com"} 2015-03-31 18:36:37 [E] PGError: ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(21) is still referenced from table "tokens". : DELETE FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."id" = $1 (ActiveRecord::InvalidForeignKey) /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1171:in `get_last_result' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1171:in `exec_cache' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:676:in `block in exec_delete' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log' /opt/rh/ruby193/root/usr/share/gems/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log' --
Created attachment 1009040 [details] Foreign_key issue still reproducible with snap8 on deleting a discovered host
Created attachment 1009043 [details] production.log
Hmmm works for me. Can you give us exact steps how to reproduce this on a cleanly installed Sat 6 ? Please note this must not be an upgrade from previous snap, you must install the snap from scratch.
Its reproducible on clean/Fresh installed Sat6 box with snap8. Steps to reproduce: ==================== 1. discover a host 2. Provision the discover host manually..But while updating the new host form, fill something with wrong value.. may be don't specify the operating system and submit the form 3. delete the host
Issue is re-producible with Sat6.1 GA snap2(Satellite-6.1.0-RHEL-7-20150429.2). On deleting a discovered host, UI raises error: - ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(2) is still referenced from table "tokens". -
Created attachment 1021734 [details] reproducible with GA snap2
Is this a clean install or an update? The migration was merged before the full fix so if this is an update it needs to be rerun before testing.
Its a clean install..without upgrade..
Opened up a related bug upstream: http://projects.theforeman.org/issues/10365 moving this to POST as the fix has been merged upstream
Scheduled for re-triage, this is a blocker. We have an upstream patch already.
This issue is also reproducible with snap4 compose2. 2015-05-15 13:32:29 [I] Processing by HostsController#destroy as HTML 2015-05-15 13:32:29 [I] Parameters: {"authenticity_token"=>"rSnD0zt242mRrI5cJhkRpZyfzHfRNJhkSAOtaKodQlY=", "id"=>"mac525400d03216.lab.eng.pnq.redhat.com"} 2015-05-15 13:32:30 [E] PGError: ERROR: update or delete on table "hosts" violates foreign key constraint "tokens_host_id_fk" on table "tokens" DETAIL: Key (id)=(11) is still referenced from table "tokens". : DELETE FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."id" = $1 (ActiveRecord::InvalidForeignKey) /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1171:in `get_last_result' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1171:in `exec_cache' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:676:in `block in exec_delete'
Moving this to verified as I tried all possible ways to reproduce the issue but looks like its fixed by all ways. Thank you for fixing it
WORKAROUND: # foreman-rake console > Token.where('id not in (?)', Host::Managed.all.map(&:token).compact).delete_all > exit Then delete the discovered host. Until this fix is delivered in 6.1 GA, this must be repeated every time you want to delete an invalid host.
This bug is slated to be released with Satellite 6.1.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2015:1592