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

remove user to prevent ForeignKeyViolation #17024

Closed

Conversation

amolpati30
Copy link
Contributor

@amolpati30 amolpati30 commented Nov 29, 2024

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.

@amolpati30 amolpati30 added CherryPick PR needs CherryPick to previous branches AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing labels Nov 29, 2024
@amolpati30 amolpati30 requested a review from a team as a code owner November 29, 2024 11:13
@amolpati30 amolpati30 marked this pull request as draft November 29, 2024 11:14
@amolpati30
Copy link
Contributor Author

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

@Satellite-QE
Copy link
Collaborator

PRT Result

Build Number: 9478
Build Status: SUCCESS
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, 116 warnings in 1043.21s (0:17:23) ==========

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Nov 29, 2024
@amolpati30 amolpati30 marked this pull request as ready for review November 29, 2024 12:12
@amolpati30 amolpati30 added 6.13.z Introduced in or relating directly to Satellite 6.13 6.14.z Introduced in or relating directly to Satellite 6.14 6.15.z Introduced in or relating directly to Satellite 6.15 6.16.z Introduced in or relating directly to Satellite 6.16 labels Nov 29, 2024
@ekohl
Copy link
Contributor

ekohl commented Nov 29, 2024

This sounds like a bug in the application to me. Was one filed?

@amolpati30
Copy link
Contributor Author

@ekohl
It might be but because we are granting only view permissions to the user, and then attempting to delete the host during teardown with that user. This behavior is likely expected, as the user does have only view permissions. Additionally, the database storing the data with a foreign key, which prevents the host from being deleted and results in an error.

@ekohl
Copy link
Contributor

ekohl commented Dec 2, 2024

If you see a PostgreSQL error as a user, I'd consider it a bug. IMHO it should either cascade (delete any permissions the user has) or provide a proper error why the user can't be deleted.

@amolpati30
Copy link
Contributor Author

A bug has already been raised for this issue - https://issues.redhat.com/browse/SAT-18656.
Therefore, I am closing this PR as it is no longer valid.

@amolpati30 amolpati30 closed this Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.13.z Introduced in or relating directly to Satellite 6.13 6.14.z Introduced in or relating directly to Satellite 6.14 6.15.z Introduced in or relating directly to Satellite 6.15 6.16.z Introduced in or relating directly to Satellite 6.16 AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing CherryPick PR needs CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants