Skip to content

fix(api): delegate concurrent deletion deadlocks to TaskBackoffError#6995

Open
SahilJat wants to merge 2 commits intoFlagsmith:mainfrom
SahilJat:fix/backend-deletion-deadlocks
Open

fix(api): delegate concurrent deletion deadlocks to TaskBackoffError#6995
SahilJat wants to merge 2 commits intoFlagsmith:mainfrom
SahilJat:fix/backend-deletion-deadlocks

Conversation

@SahilJat
Copy link

Thanks for submitting a PR! Please check the boxes below:

  • [ x ] I have read the Contributing Guide.
  • [ x ] I have added information to docs/ if required so people know about the feature.
  • [ x ] I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #6878

Please describe.
1.Wrapped the deletion queries in environments/tasks.py and features/tasks.py with specific exception handlers for OperationalError, IntegrityError, and TransactionManagementError.
2. Delegated the retry mechanism by raising TaskBackoffError.
3. This allows the first worker to hold the lock and complete its softdelete cascade, while the colliding worker gracefully yields, backs off, and safely retries without polluting Sentry with unhandled DB exceptions.

How did you test this code?

Please describe.

@SahilJat SahilJat requested a review from a team as a code owner March 19, 2026 14:13
@SahilJat SahilJat requested review from emyller and removed request for a team March 19, 2026 14:13
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.

Once credits are available, reopen this pull request to trigger a review.

@vercel
Copy link

vercel bot commented Mar 19, 2026

@SahilJat is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the api Issue related to the REST API label Mar 19, 2026
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.23%. Comparing base (67fa5fd) to head (e7cf0a6).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
api/environments/tasks.py 71.42% 2 Missing ⚠️
api/features/tasks.py 71.42% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (71.42%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6995      +/-   ##
==========================================
- Coverage   98.31%   98.23%   -0.09%     
==========================================
  Files        1335     1335              
  Lines       49784    49669     -115     
==========================================
- Hits        48947    48793     -154     
- Misses        837      876      +39     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race conditions in delete_environment and delete_feature tasks cause deadlocks and FK violations

1 participant