dj-stripe / dj-stripe

dj-stripe automatically syncs your Stripe Data to your local database as pre-implemented Django Models allowing you to use the Django ORM, in your code, to work with the data making it easier and faster.
https://dj-stripe.dev
MIT License
1.56k stars 474 forks source link

SubscriptionItem id not found after SubscriptionSchedule phase change #2025

Open PabloCastellano opened 3 months ago

PabloCastellano commented 3 months ago

Describe the bug

I have updated the Price of a Subscription using a SubscriptionSchedule. The SubscriptionSchedule worked fine and now the price is updated. However after the change, the invoice events failed in my backend due to "Invalid subscription_item id: si_LgHurTfBkdLkwd".

The subscription item existed in the database before the phase change. My gut feeling is that dj-stripe has removed it when the event customer.subscription.updated was received. This event changed the items in the subscription (there I could still see the subscriptionitem id in the previous_attributes field).

Not sure if it matters, but both prices (previous and new) depend on customer usage and have two tiers: free up to 1000 and paid from 1000 onwards.

After chatting to Stripe dev support, it looks like the invoice was created because of the schedule phase change, and an hour later it was finalized. Because the phase change got rid of that subscription item, it wasn't accessible when trying to access it via the API. They confirmed this is something that has to be fixed in dj-stripe.

Failing events:

Traceback: Sentry

To Reproduce

  1. Create a Subscription with one tiered SubscriptionItem
  2. Add some usage to the SubscriptionItem
  3. Create a SubscriptionSchedule for the Subscription
  4. Wait until the schedule changes the phase of the Subscription

Software versions