Cannot delete a security policy project
Summary
Trying to delete a security policy project fails with following error:
gitlabhq_development=# SELECT delete_error FROM projects WHERE id=<id>;
delete_error |
---|
PG::ForeignKeyViolation: ERROR: update or delete on table "projects" violates foreign key constraint "fk_rails_42ed6c25ec" on table "security_orchestration_policy_configurations" DETAIL: Key (id)=(64) is still referenced from table "security_orchestration_policy_configurations". |
Steps to reproduce
- Create a policy following the instructions
- Open the newly created policy project (with name
<project name> - Security policy project
) - Delete the policy project
Example Project
https://gitlab.com/sashi_kumar/container-scanning-match-security-policy-project
What is the current bug behavior?
The project exists without the repository.
What is the expected correct behavior?
Project should be deleted
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
diff --git a/ee/app/models/ee/project.rb b/ee/app/models/ee/project.rb
index 34c6e2b34b5..48e1249276b 100644
--- a/ee/app/models/ee/project.rb
+++ b/ee/app/models/ee/project.rb
@@ -102,7 +102,7 @@ def lock_for_confirmation!(id)
has_many :incident_management_oncall_rotations, class_name: 'IncidentManagement::OncallRotation', through: :incident_management_oncall_schedules, source: :rotations
has_many :incident_management_escalation_policies, class_name: 'IncidentManagement::EscalationPolicy', inverse_of: :project
- has_one :security_orchestration_policy_configuration, class_name: 'Security::OrchestrationPolicyConfiguration', foreign_key: :project_id, inverse_of: :project
+ has_one :security_orchestration_policy_configuration, class_name: 'Security::OrchestrationPolicyConfiguration', inverse_of: :project
has_many :security_scans, class_name: 'Security::Scan', inverse_of: :project
Edited by Sashi Kumar Kumaresan