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

[6.15.z] remove user to prevent ForeignKeyViolation #17534

Open
wants to merge 1 commit into
base: 6.15.z
Choose a base branch
from

Conversation

Satellite-QE
Copy link
Collaborator

Cherrypick of PR: #17024

Problem -
When creating another user with a specific role and adding resources in the filter with the 'view_facts' permission, an error occurred ('PG::ForeignKeyViolation: ERROR: update or delete on table "hosts" violates foreign key constraint "fact_values_host_id_fk" on table "fact_values"') during the teardown process while deleting the host. This happened because a user with only view permissions existed for the host and making it impossible to update or delete the user associated with the fact.

Solution -
To prevent this error, the user was removed before the teardown process.

xremove user to prevent ForeignKeyViolation

(cherry picked from commit c2acadb)
@Satellite-QE Satellite-QE added 6.15.z Introduced in or relating directly to Satellite 6.15 Auto_Cherry_Picked Automatically cherrypicked PR using GHA labels Feb 6, 2025
@Satellite-QE Satellite-QE requested a review from a team as a code owner February 6, 2025 12:36
@Satellite-QE Satellite-QE added the No-CherryPick PR doesnt need CherryPick to previous branches label Feb 6, 2025
@Satellite-QE
Copy link
Collaborator Author

trigger: test-robottelo
pytest: tests/foreman/api/test_ansible.py::TestAnsibleCfgMgmt -k test_positive_read_facts_with_filter

@Satellite-QE Satellite-QE added the AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing label Feb 6, 2025
@Satellite-QE
Copy link
Collaborator Author

PRT Result

Build Number: 10099
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/api/test_ansible.py::TestAnsibleCfgMgmt -k test_positive_read_facts_with_filter --external-logging
Test Result : ===== 2 passed, 3 deselected, 138 warnings, 2 errors in 1367.65s (0:22:47) =====

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Feb 6, 2025
@amolpati30
Copy link
Contributor

trigger: test-robottelo
pytest: tests/foreman/api/test_ansible.py::TestAnsibleCfgMgmt -k test_positive_read_facts_with_filter

@Satellite-QE
Copy link
Collaborator Author

PRT Result

Build Number: 10105
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/api/test_ansible.py::TestAnsibleCfgMgmt -k test_positive_read_facts_with_filter --external-logging
Test Result : ===== 2 passed, 3 deselected, 131 warnings, 1 error in 1200.00s (0:20:00) ======

@@ -296,6 +296,9 @@ def test_positive_read_facts_with_filter(
host.organization = module_org
host.location = module_location
host.update(['organization', 'location'])
request.addfinalizer(
user.delete
) # Adding a temporary workaround until the issue 'SAT-18656' is resolved.
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is a temporary workaround, why isn't there a condition for that issue being resolved? The same for the original PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Earlier, I tried using the condition, but it didn't work. So, I attempted this approach instead. However, the issue is that this change works sometimes but not consistently. I'm not sure why the behavior varies.

@lhellebr
Copy link
Contributor

lhellebr commented Feb 6, 2025

In PRT:

{\'error\': {\'message\': \'PG::ForeignKeyViolation: ERROR:  update or delete on table "hosts" violates foreign key constraint "fact_values_host_id_fk" on table "fact_values"\\nDETAIL:  Key (id)=(5) is still referenced from table "fact_values".\\n\'}})')"

It seems like the test actually caught that exact issue, perhaps meaning that the workaround doesn't work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.15.z Introduced in or relating directly to Satellite 6.15 Auto_Cherry_Picked Automatically cherrypicked PR using GHA AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing No-CherryPick PR doesnt need CherryPick to previous branches PRT-Failed Indicates that latest PRT run is failed for the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants