Dj-stripe: Cancelling a Subscription removes the model instance

Created on 25 Oct 2017  路  6Comments  路  Source: dj-stripe/dj-stripe

I notice at the moment when you cancel a subscription the model instance is deleted too and looking at the code this seems to be by design. Is this the correct action to take - surely having the history would be useful and would there not be foreign keys to invoices etc? What purpose is the subscription status of "cancelled" if the records are deleted? I also noticed that the Customer._sync_subscriptions() method pulls in all subscriptions regardless of their status so the functionality at least seems to be inconsistent.

Most helpful comment

I'd be willing to bet the reason for it is Stripe's old behaviour with listing cancelled subscriptions. I had to make some updates to that when I updated dj-stripe for the 2017- apis. Either way, yeah, we should be keeping them.

All 6 comments

It seems Customer._sync_invoices() will import the canceled subscriptions too

@jleclanche @lskillen thoughts? Keeping cancelled subscriptions would be ideal, but I remember there being some reason for this deletion

I'd be willing to bet the reason for it is Stripe's old behaviour with listing cancelled subscriptions. I had to make some updates to that when I updated dj-stripe for the 2017- apis. Either way, yeah, we should be keeping them.

Any updates on this?

Closing as dupe of #576 since it's the same underlying issue: We're handling the .deleted webhooks wrong.

I worked around this problem in my fork as follows:

in event_handlers.py:

@webhooks.handler("customer.subscription")
def customer_subscription_webhook_handler(event):
    """Handle updates to customer subscription objects.
    Docs an example subscription webhook response: https://stripe.com/docs/api#subscription_object
    """
    # XXX workaround: don't delete canceled subscriptions
    crud_type = CrudType.determine(event=event)
    if crud_type.deleted:
        crud_type = CrudType(updated=True)
    _handle_crud_like_event(target_cls=Subscription, event=event, crud_type=crud_type)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lskillen picture lskillen  路  4Comments

Guest007 picture Guest007  路  6Comments

mbaragiola picture mbaragiola  路  4Comments

therefromhere picture therefromhere  路  4Comments

jleclanche picture jleclanche  路  6Comments