fix: issue deletion failing due to foreign key constraint on IssueComments#5393
fix: issue deletion failing due to foreign key constraint on IssueComments#5393
Conversation
…ents Delete associated IssueComments before deleting the parent Issue to prevent MySQL foreign key constraint violations (#5392). https://claude.ai/code/session_01C6A9d6G8T4ywwTkTwz4vp3
Verify that associated IssueComments are deleted before the parent Issue, and that comments from unrelated issues are not affected. https://claude.ai/code/session_01C6A9d6G8T4ywwTkTwz4vp3
🦈 RepoShark Health Check
View full analysis → · Powered by RepoShark |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughDeleteIssue now loads and deletes all IssueComments for the target issue, then deletes the issue; tests were added/updated to verify associated comments are removed before the issue deletion. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant IssuesController
participant IssueCommentsRepo as IssueComments
participant IssuesRepo as Issues
participant Notifier
Client->>IssuesController: DELETE /issues/{id}
IssuesController->>IssueComments: GetAll() -> filter IssuesId == id
IssueComments-->>IssuesController: [comment1, comment2]
IssuesController->>IssueComments: DeleteRange([comment1, comment2])
IssueComments-->>IssuesController: OK
IssuesController->>Issues: Delete(issue)
Issues-->>IssuesController: OK
IssuesController->>Notifier: Send IssueDeleted notification
IssuesController-->>Client: 204 No Content
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ❌ 3❌ Failed checks (3 warnings)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 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 |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/Ombi/Controllers/V1/IssuesController.cs (1)
309-314: Prefer batched comment deletion to avoid N database writes.Line 310–313 currently performs one delete/save per comment. Use
DeleteRangeto reduce round-trips and tighten the deletion path.💡 Suggested change
- var comments = await _issueComments.GetAll().Where(x => x.IssuesId == id).ToListAsync(); - foreach (var comment in comments) - { - await _issueComments.Delete(comment); - } + var comments = await _issueComments.GetAll().Where(x => x.IssuesId == id).ToListAsync(); + if (comments.Count > 0) + { + await _issueComments.DeleteRange(comments); + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Ombi/Controllers/V1/IssuesController.cs` around lines 309 - 314, The current loop fetches comments via _issueComments.GetAll().Where(x => x.IssuesId == id).ToListAsync() and deletes them one-by-one using _issueComments.Delete(comment), causing N database writes; replace the per-comment deletes with a single batched call (e.g., _issueComments.DeleteRange(comments) or an equivalent repository method) so the controller uses one delete/save operation for the entire collection and removes the foreach that calls Delete for each comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Ombi.Tests/IssuesControllerTests.cs`:
- Around line 148-182: The test
DeleteIssue_DeletesAssociatedComments_BeforeDeletingIssue currently verifies
deletions occurred but not their order; update the test to assert that comment
deletions happen before the issue deletion by using Moq's MockSequence (or
equivalent) to set ordered expectations: create a MockSequence, call
_comments.InSequence(sequence).Setup(x =>
x.Delete(comment1)).Returns(Task.CompletedTask) and similarly for comment2, then
_issues.InSequence(sequence).Setup(x =>
x.Delete(issue)).Returns(Task.CompletedTask), keep other setups the same, and
remove or keep the existing Verify presence assertions—the sequence asserts
ordering so the test enforces "before deleting issue" contract.
---
Nitpick comments:
In `@src/Ombi/Controllers/V1/IssuesController.cs`:
- Around line 309-314: The current loop fetches comments via
_issueComments.GetAll().Where(x => x.IssuesId == id).ToListAsync() and deletes
them one-by-one using _issueComments.Delete(comment), causing N database writes;
replace the per-comment deletes with a single batched call (e.g.,
_issueComments.DeleteRange(comments) or an equivalent repository method) so the
controller uses one delete/save operation for the entire collection and removes
the foreach that calls Delete for each comment.
🪄 Autofix (Beta)
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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e348a94e-75d9-4fd5-a0bf-ffd5ac862883
📒 Files selected for processing (2)
src/Ombi.Tests/IssuesControllerTests.cssrc/Ombi/Controllers/V1/IssuesController.cs
Ombi Automation
|
||||||||||||||||||||||||||||
| Project |
Ombi Automation
|
| Branch Review |
claude/fix-issue-5392-IX2fH
|
| Run status |
|
| Run duration | 06m 32s |
| Commit |
|
| Committer | Jamie Rees |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
2
|
|
|
4
|
|
|
0
|
|
|
103
|
| View all changes introduced in this branch ↗︎ | |
…n test Address review feedback: replace per-comment Delete loop with a single DeleteRange call, and assert that comments are deleted before the issue using callback-based ordering verification. https://claude.ai/code/session_01C6A9d6G8T4ywwTkTwz4vp3
|
|
🎉 Thank you for your contribution! Your changes have been successfully merged and will be included in the next release. What you contributed:
Thank you for helping make Ombi better! 🙏 |



Delete associated IssueComments before deleting the parent Issue to
prevent MySQL foreign key constraint violations (#5392).
Summary by CodeRabbit
Bug Fixes
Tests