Skip to content

fix: issue deletion failing due to foreign key constraint on IssueComments#5393

Merged
tidusjar merged 3 commits intodevelopfrom
claude/fix-issue-5392-IX2fH
Apr 8, 2026
Merged

fix: issue deletion failing due to foreign key constraint on IssueComments#5393
tidusjar merged 3 commits intodevelopfrom
claude/fix-issue-5392-IX2fH

Conversation

@tidusjar
Copy link
Copy Markdown
Member

@tidusjar tidusjar commented Apr 8, 2026

Delete associated IssueComments before deleting the parent Issue to
prevent MySQL foreign key constraint violations (#5392).

Summary by CodeRabbit

  • Bug Fixes

    • Deleting an issue now also removes its associated comments first, preventing orphaned comments and ensuring data consistency.
  • Tests

    • Added and updated tests to verify associated comments are deleted before the issue and that deletion order is enforced.

tidusjar added 2 commits April 8, 2026 06:11
…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
Copy link
Copy Markdown

reposhark bot commented Apr 8, 2026

🦈 RepoShark Health Check

Metric Value
Health Score 🔴 55/100 ⚠️ -4
PR Size S

View full analysis → · Powered by RepoShark

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2344c52f-e99d-49d6-bec1-2ec606f3c629

📥 Commits

Reviewing files that changed from the base of the PR and between 20f2e82 and c08d2f5.

📒 Files selected for processing (2)
  • src/Ombi.Tests/IssuesControllerTests.cs
  • src/Ombi/Controllers/V1/IssuesController.cs
✅ Files skipped from review due to trivial changes (1)
  • src/Ombi.Tests/IssuesControllerTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Ombi/Controllers/V1/IssuesController.cs

📝 Walkthrough

Walkthrough

DeleteIssue 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

Cohort / File(s) Summary
Controller logic
src/Ombi/Controllers/V1/IssuesController.cs
Load issue comments for id, call IssueComments.DeleteRange(comments) with materialised list, then delete the issue (preserves existing notification flow).
Tests
src/Ombi.Tests/IssuesControllerTests.cs
Updated existing test to mock IssueComments.GetAll() and DeleteRange(...); added DeleteIssue_DeletesAssociatedComments_BeforeDeletingIssue to assert only associated comments are deleted and that deletion order is comments → issue.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

Poem

🐰
I dug through comments, one by one,
Cleared their crumbs beneath the sun,
Then nuzzled issue, soft and sweet—
No orphans left, the job's complete.

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The pull request title does not follow the Conventional Commits specification required for this repository. Update the title to follow the format 'fix: '. Example: 'fix: prevent foreign key constraint violation when deleting issues with comments'
Description check ⚠️ Warning The pull request description is incomplete and does not follow the required template structure with all necessary sections. Expand the description to include all template sections: Description, Related Issues, Testing, Checklist items, Type of Change, and Additional Notes. Add details about what testing was performed and confirm checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/fix-issue-5392-IX2fH

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tidusjar
Copy link
Copy Markdown
Member Author

tidusjar commented Apr 8, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 DeleteRange to 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1130d3e and 20f2e82.

📒 Files selected for processing (2)
  • src/Ombi.Tests/IssuesControllerTests.cs
  • src/Ombi/Controllers/V1/IssuesController.cs

Comment thread src/Ombi.Tests/IssuesControllerTests.cs
@cypress
Copy link
Copy Markdown

cypress bot commented Apr 8, 2026

Ombi Automation    Run #2781

Run Properties:  status check passed Passed #2781  •  git commit 48ced51836 ℹ️: Merge c08d2f551b709219c3c829119bd1c0c8ef736eb6 into 1130d3e437da104e5f03b0303e53...
Project Ombi Automation
Branch Review claude/fix-issue-5392-IX2fH
Run status status check passed Passed #2781
Run duration 06m 32s
Commit git commit 48ced51836 ℹ️: Merge c08d2f551b709219c3c829119bd1c0c8ef736eb6 into 1130d3e437da104e5f03b0303e53...
Committer Jamie Rees
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 2
Tests that did not run due to a developer annotating a test with .skip  Pending 4
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 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
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

@tidusjar tidusjar changed the title Fix issue deletion failing due to foreign key constraint on IssueComments fix: issue deletion failing due to foreign key constraint on IssueComments Apr 8, 2026
@tidusjar tidusjar merged commit bfd4166 into develop Apr 8, 2026
22 of 23 checks passed
@tidusjar tidusjar deleted the claude/fix-issue-5392-IX2fH branch April 8, 2026 07:57
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

🎉 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! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant