Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2012897 - When removing an associated CR host from Satellite it fails as 'PG::ForeignKeyViolation'.
Summary: When removing an associated CR host from Satellite it fails as 'PG::ForeignKe...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Compute Resources
Version: 6.9.0
Hardware: Unspecified
OS: Unspecified
high
high with 3 votes
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Satellite QE Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-10-11 14:39 UTC by Rudnei Bertol Jr.
Modified: 2024-12-20 21:22 UTC (History)
19 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-08-10 16:21:15 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker SAT-12638 0 None None None 2022-09-01 05:19:11 UTC
Red Hat Knowledge Base (Solution) 4529531 0 None None None 2022-06-08 07:59:45 UTC
Red Hat Knowledge Base (Solution) 6524891 0 None None None 2022-06-08 07:59:45 UTC

Description Rudnei Bertol Jr. 2021-10-11 14:39:19 UTC
Description of problem:

When deleting a host that is 'Associated' to a computer resource, and there is a 'before_update' hook configured on the Satellite it, fails to delete the host like the following output.

~~~
PG::ForeignKeyViolation: ERROR: update or delete on table "hosts" violates foreign key constraint "host_status_hosts_host_id_fk" on table "host_status" DETAIL: Key (id)=(HOST_ID) is still referenced from table "host_status".
~~~

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

Satellite 6.9


How reproducible:

There is a reproducer configured in our laboratory.


Steps to Reproduce:
1. 
2.
3.

Actual results:

It is failing to delete a host.


Expected results:

The host should be deleted smoothly.

Additional info:

Comment 13 Brad Buckingham 2023-08-10 16:21:15 UTC
The team has been unable to reproduce the behavior described on Satellite 6.12.z, 6.13.z and the upcoming 6.14.0 (internal builds) release.  For this reason, we are moving this to CLOSED:CURRENTRELEASE.

If there are concerns or the issue persists, please feel free to re-open providing details to reproduce.

Thanks!

Comment 14 hakon.gislason 2023-08-21 09:26:33 UTC
Just ran into this issue on satellite-6.13.3-1.el8sat.noarch.

PG::ForeignKeyViolation: ERROR: update or delete on table "hosts" violates foreign key constraint "host_status_hosts_host_id_fk" on table "host_status" DETAIL: Key (id)=(8386) is still referenced from table "host_status".

I tried the resolution in https://access.redhat.com/solutions/6524891 but that did not work. Is there a workaround?


root@iu-satellite:~# foreman-rake console
Loading production environment (Rails 6.1.7)
irb(main):001:0> host = Host.find_by(:name => 'ru-ansible-molecule-el7-1.decode.is')
=> #<Host::Managed id: 8386, name: "ru-ansible-molecule-el7-1.decode.is", last_compile: "2023-05-31 22:23:09.000000000 +0000", last_report: [FILTERED], updated_at: "2023-08-21 09:17:05.879189000 +0000", created_at: "2023-03-24 15:34:18.594942000 +0000", root_pass: [FILTERED], architecture_id: 1, operatingsystem_...
irb(main):002:0> host.update_attribute(:managed, false)
=> true
irb(main):004:0> host.disassociate!
=> true
irb(main):005:0> host.destroy!
Traceback (most recent call last):
        2: from lib/tasks/console.rake:5:in `block in <top (required)>'
        1: from (irb):5
ActiveRecord::InvalidForeignKey (PG::ForeignKeyViolation: ERROR:  update or delete on table "hosts" violates foreign key constraint "host_status_hosts_host_id_fk" on table "host_status")
DETAIL:  Key (id)=(8386) is still referenced from table "host_status".
irb(main):006:0>

Comment 15 Sayan Das 2023-08-21 09:32:42 UTC

Hello

The following within foreman-rake console will get rid of the different Host Statues and you should no longer run into that violation 

h = Host.find_by(:name => 'ru-ansible-molecule-el7-1.decode.is')
HostStatus::Status.where(host_id: h.id).delete_all


STEP 4 from https://access.redhat.com/solutions/4529531 contains the entire sequence of host deletion by rake console

Comment 16 hakon.gislason 2023-08-21 09:46:23 UTC
Thanks, that worked.

Please add that to the knowledgebase solution article.

Comment 17 Sayan Das 2023-08-21 09:59:21 UTC
Good to hear that it worked. 

It was done almost the same time when I posted the solution. That KB now also points to https://access.redhat.com/solutions/4529531 for additional steps of deletion via rake console ( if needed by someone )


Note You need to log in before you can comment on or make changes to this bug.