fix: delete branches after content delivery configs in hard delete - #3853
fix: delete branches after content delivery configs in hard delete#3853bdshadow wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughProject hard deletion now removes content delivery configurations before branches, flushes branch deletions, and then continues cleanup. A regression test covers projects with branch-based content delivery configurations and verifies that hard deletion removes the project. ChangesProject hard deletion
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
hardDeleteProject deleted branches before content_delivery_config rows, which reference branch via branch_id, so deleting a project that had branch-scoped content delivery configs failed with a foreign key violation. This aborted the orphan-project purge batch in production, leaving projects of deleted organizations undeleted. Move branchService.deleteAllByProjectId after the ContentDeliveryConfig deletion, and flush right after it so the branch removals (done through the persistence context) reach the DB before the project row is deleted (branch.project_id references project).
537cb6b to
08badd6
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@backend/app/src/test/kotlin/io/tolgee/service/project/ProjectHardDeletingServiceTest.kt`:
- Around line 139-140: Assign the newly created
ContentDeliveryConfigBranchingTestData instance to testDataToClean before
calling testDataService.saveTestData, so cleanTestDataAfterTest can remove the
fixture during `@AfterEach` cleanup.
In
`@backend/data/src/main/kotlin/io/tolgee/service/project/ProjectHardDeletingService.kt`:
- Around line 189-190: Update the branch deletion sequence in
ProjectHardDeletingService to call entityManager.clear() immediately after
entityManager.flush(), ensuring the persistence context is cleared before
subsequent bulk deletes.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e440cbbd-9d88-4e18-b8a9-8285a4320b25
📒 Files selected for processing (2)
backend/app/src/test/kotlin/io/tolgee/service/project/ProjectHardDeletingServiceTest.ktbackend/data/src/main/kotlin/io/tolgee/service/project/ProjectHardDeletingService.kt
Problem
The orphan-project purge scheduler (
DeletedOrganizationProjectPurgeScheduler→ProjectHardDeletingService.hardDeleteProject) is failing in production and leaving projects of deleted organizations undeleted (deleted_atset on the org, projects never removed).Sentry shows the current failure:
hardDeleteProjectdeleted branches (branchService.deleteAllByProjectId) before thecontent_delivery_configrows, which referencebranchviabranch_id. A single project with branch-scoped content delivery configs is enough to throw, and because the scheduler processes projects in a batch, that one project aborts the whole purge run — which is why deleted-org projects keep piling up.Fix
branchService.deleteAllByProjectIdto run after theContentDeliveryConfigdeletion.branchServiceload-and-removes the branch entities, which previously reached the DB via theflush()that immediately followed the old call site. Moving the call without a flush left the branches in the session, soDELETE FROM Projectthen failed onbranch.project_id → project. The explicit flush pushes the branch removals to the DB before the project row is deleted.Audited all 9 FKs into
branch; every other referencing table (key,import,task,language_stats, and the branch-internal ones) is already deleted before branches —content_delivery_configwas the only one out of order.Test
Adds
deletes project with content delivery configs on branchestoProjectHardDeletingServiceTest, using the existingContentDeliveryConfigBranchingTestData(CDN configs onmain/featurebranches). It reproduced both FK violations before the fix and passes now; the full suite is green.Context
Follow-up to the same purge-path FK-ordering work as #3810 — this is the next constraint the scheduler surfaced once the earlier imports/tasks gaps were fixed.
Summary by CodeRabbit