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

Delete TLS certificate sources when deleting users #1334

Merged

Conversation

timopollmeier
Copy link
Member

@timopollmeier timopollmeier commented Oct 22, 2020

What:
The delete_tls_certificates_user function now also removes the referenced
rows from tls_certificate_sources, tls_certificate_locations and
tls_certificate_origins.

Why:
This caused foreign key constraint violations when deleting a user owning
any TLS certificates.

How:
Tested this by creating a new user, importing a report with TLS certificates and then trying to delete the user without an inheritor.
With the patch this should work, whereas it caused an error like this before:

sql_exec_internal: PQexec failed: ERROR:  update or delete on table "tls_certificates" violates foreign key constraint "tls_certificate_sources_tls_certificate_fkey" on table "tls_certificate_sources"
DETAIL:  Key (id)=(806) is still referenced from table "tls_certificate_sources".

Checklist:

The delete_tls_certificates_user function did not remove the referenced
rows from tls_certificate_sources, tls_certificate_locations and
tls_certificate_origins, causing foreign key constraint violations.
@timopollmeier timopollmeier marked this pull request as ready for review October 22, 2020 15:26
Copy link
Contributor

@bjoernricks bjoernricks left a comment

Choose a reason for hiding this comment

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

Just a question besides the PR is looking good to me, why aren't we using ON DELETE CASCADE more often especially for something like this?

@timopollmeier
Copy link
Member Author

In older versions using SQLite we did not use any constraints, so the default style was to remove referenced rows explicitly.
Doing this should also serve as a reminder to remove referenced rows that do not use a foreign key constraint.
Perhaps this could be changed if we use foreign keys more consistently.

@timopollmeier timopollmeier merged commit 3a1f070 into greenbone:gvmd-20.08 Oct 23, 2020
@timopollmeier timopollmeier deleted the fix-delete-user-tls-certs branch October 15, 2021 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants