-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Subscriptions: avoid double deletion #9341
Conversation
Subscription is set to cascade delete when an organization is deleted, with this additional signal we are cancelling the subscription twice, and stripe is given an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are we canceling the subscription on Stripe when the organization is deleted?
readthedocs.org/readthedocs/subscriptions/signals.py Lines 16 to 17 in 97ee9ba
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand these changes.
Subscription is set to cascade delete when an organization is deleted
If the Subscription
is set to CASCADE, it won't trigger Django signals and then
readthedocs.org/readthedocs/subscriptions/signals.py
Lines 16 to 17 in 97ee9ba
@receiver(pre_delete, sender=Subscription) | |
def remove_stripe_subscription(sender, instance, using, **kwargs): |
I think we need to connect remove_stripe_subscription
to pre_delete
on Organization
. Otherwise, it won't be executed.
If I'm not correct, can you please explain to me the flow happening when an organization is deleted by the user?
It will, when you delete an org, all their related objects will be deleted as you manually called |
I think you are confused about this, However, the last sentence says,
I understand that "for all deleted objects" only applies to the original objects, not the CASCADEd ones because Django does not really know what are those objects, so it can't trigger those signals for them. I want to be 100% sure that we are understanding exactly how it works because I want to prevent any issues with the subscriptions that are hard to detect and affect directly our income and onboarding UX + support time, etc |
https://docs.djangoproject.com/en/4.0/topics/db/queries/#topics-db-queries-delete In any way, we have tests for this at .com (se also |
These signals are sent to all deleted objects, including the CASCADEd ones. I just confirmed that by doing a local test. This is the answer I was expecting from you with my original comment asking about how it's the flow of execution calls: #9341 (review) I executed this code:
Without this PR's changes:
With this PR's changes:
|
It would be good to update this PR to a mergeable state since we are still hitting this issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this by myself to find out the answer to my question. Everything looks good, I think. Hopefully, we don't screw things related to subscriptions on production again 🙃
Subscription is set to cascade delete
when an organization is deleted,
with this additional signal
we are cancelling the subscription twice,
and stripe is given an error.