Fix project state getting out of sync when deletion fails
What does this MR do and why?
Fixes a bug where the project state gets stuck to deletion_scheduled when an errors occurs in the Project::UpdateService during deletion. This MR does two things:
- Ensure that the transaction block for rollbacks correctly when the update operations fails.
- Derive deletion state from new state metadata values. Allowing previously bugged projects from getting restored to normal state.
Note for backend reviewers
This touches quite a lot of files. I would recommend that you please review the changes commit-by-commit to hopefully make it easier to understand:
- Fix project state getting out of sync when deletion fails
- Use state metadata column for deletion checks
References
Related to #586253 (closed)
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
Validate that it prevents states from getting out of sync
- Apply the following patch to simulate a failure
Index: app/services/projects/update_service.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb
--- a/app/services/projects/update_service.rb (revision 97e55fb014f7cabd926a3eec80be6cff1ce5ae7b)
+++ b/app/services/projects/update_service.rb (date 1768469120710)
@@ -10,6 +10,8 @@
ApiError = Class.new(StandardError)
def execute
+ raise ValidationError, 'Oh no, something went wrong.'
+
build_topics
ensure_ci_cd_settings
remove_unallowed_params
- Go to
Project > Settings > General > Delete project. - Retry deleting the project.
Before: The operation fails due to invalid state transition.
After: The operation should fail with the same error message ('Oh no, something went wrong.').
Validate that corrupted projects can be restored to normal state
- Call
Project.find(...).schedule_deletionin the rails console. - Go to the
Project > Settings > General > Restore project.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Shane Maglangit