Dj-stripe: Subscription.start is updated when subscription is canceled

Created on 6 Mar 2019  路  1Comment  路  Source: dj-stripe/dj-stripe

When I cancel a subscription, Subscription.start is also updated to the date when the subscription was canceled. I haven't investigated deeper but this behaviour looks wrong. According to the code, Subscription.start is the "date the subscription started".

https://github.com/dj-stripe/dj-stripe/blob/4490fda09e5888da82499f1e17ecf883b00b36c6/djstripe/models/billing.py#L963

Here is the trace of the commands I ran

>>> su = Subscription.objects.last()
>>> su.cancel_at_period_end
False
>>> su.start
datetime.datetime(2019, 3, 6, 14, 47, 51, tzinfo=<UTC>)
>>> su.current_period_start
datetime.datetime(2019, 3, 6, 14, 47, 51, tzinfo=<UTC>)
>>> su.current_period_end
datetime.datetime(2019, 3, 31, 22, 0, tzinfo=<UTC>)

>>> su.cancel()
<Subscription: *****@*****.*** on  **************>

>>> su = Subscription.objects.last()
>>> su.cancel_at_period_end
True
>>> su.start
datetime.datetime(2019, 3, 6, 15, 44, 29, tzinfo=<UTC>)
>>> su.current_period_start
datetime.datetime(2019, 3, 6, 14, 47, 51, tzinfo=<UTC>)
>>> 
>>> su.current_period_end
datetime.datetime(2019, 3, 31, 22, 0, tzinfo=<UTC>)
>>> su.canceled_at
datetime.datetime(2019, 3, 6, 15, 44, 29, tzinfo=<UTC>)
bug

Most helpful comment

I noticed the same thing, according to stripe's documentation for the subscription object, the start attribute is the date of the last substantial change to this subscription (the name is misleading). The method is_status_temporarily_current on the Subscription model will always return False because self.start will always equal self.cancelled_at.

Maybe something like this could work ?

def is_status_temporarily_current(self):
    return (self.canceled_at and self.cancel_at_period_end and datetime.utcnow().replace(tzinfo=utc) < self.current_period_end)

>All comments

I noticed the same thing, according to stripe's documentation for the subscription object, the start attribute is the date of the last substantial change to this subscription (the name is misleading). The method is_status_temporarily_current on the Subscription model will always return False because self.start will always equal self.cancelled_at.

Maybe something like this could work ?

def is_status_temporarily_current(self):
    return (self.canceled_at and self.cancel_at_period_end and datetime.utcnow().replace(tzinfo=utc) < self.current_period_end)
Was this page helpful?
0 / 5 - 0 ratings