Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: subscription info cache race condition #4518

Merged
merged 2 commits into from
Aug 19, 2024

Conversation

matthewelwell
Copy link
Contributor

Changes

Fixes race condition(s) related to the cancellation of a subscription. Related sentry issue here.

As far as I can tell from doing some manual testing locally by running the API and pointing it to the staging database, there were likely 2 issues in the code here:

  1. There was a BEFORE_DELETE hook on the organisation model which cancelled the subscription if it was paid. This involved deleting the related OrganisationSubscriptionInformationCache object, but the execution path then continued to delete the organisation, and subsequently try and cascade delete the OSIC object. This would fail (seemingly only some of the time).
  2. When a subscription is cancelled in chargebee, that also triggers a webhook which will execute the same code and try to delete the OSIC object which possibly won't exist depending on when the webhook is triggered / received.

How did you test this code?

I have updated a unit test to test the new behaviour, however, (perhaps more importantly) I have also tested this locally to confirm I can delete an organisation that I was previously unable to delete due to the related sentry issue.

@matthewelwell matthewelwell requested a review from a team as a code owner August 19, 2024 16:25
@matthewelwell matthewelwell requested review from zachaysan and removed request for a team August 19, 2024 16:25
Copy link

vercel bot commented Aug 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Aug 19, 2024 4:25pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Aug 19, 2024 4:25pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Aug 19, 2024 4:25pm

@matthewelwell matthewelwell changed the title Fix/subscription info cache race condition fix: subscription info cache race condition Aug 19, 2024
@github-actions github-actions bot added the api Issue related to the REST API label Aug 19, 2024
Copy link
Contributor

github-actions bot commented Aug 19, 2024

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-4518 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-4518 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-4518 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-4518 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-4518 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-4518 Finished ✅ Results

Copy link
Contributor

github-actions bot commented Aug 19, 2024

Uffizzi Preview deployment-55360 was deleted.

Copy link

codecov bot commented Aug 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.91%. Comparing base (19bc58e) to head (46d599d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4518   +/-   ##
=======================================
  Coverage   96.91%   96.91%           
=======================================
  Files        1178     1178           
  Lines       39515    39528   +13     
=======================================
+ Hits        38296    38310   +14     
+ Misses       1219     1218    -1     

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

Copy link
Contributor

@novakzaballa novakzaballa left a comment

Choose a reason for hiding this comment

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

LGTM

@matthewelwell matthewelwell added this pull request to the merge queue Aug 19, 2024
Merged via the queue into main with commit d273679 Aug 19, 2024
35 checks passed
@matthewelwell matthewelwell deleted the fix/subscription-info-cache-race-condition branch August 19, 2024 17:57
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.

2 participants