Are SubscriptionItems supposed to sync automatically?
See original GitHub issueDescribe the bug
Thank you for creating this library. My issue is that SubscriptionItems don’t seem to automatically sync through any webhook from Stripe, even with all webhook events enabled, and no errors thrown during webhook event processing or validation.
Quick question
As a first pass, can you please clarify if we’re expected to sync updates to these nested structures (e.g. SubscriptionItem) on our own, or if they’re expected to be handled by the library automatically.
Details / Longer question
I spent some time looking through the djstripe code and could not find where the nested objects (e.g. SubscriptionItem or InvoiceItems) are updated. I did find where SubscriptionItems are retrieved which is used as part of the _attach_objects_post_save_hook()
call here. But based on my understanding of the code, since the SubscriptionItem already exists in the database, we will just return early here with the value that is already in the database, and never sync the latest SubscriptionItem. Please let me know if i’ve misunderstood the code.
I can of course manually sync the subscription items with SubscriptionItem.sync_from_stripe()
in my own webhook handler, but I can’t find it documented anywhere that it is expected for the client to do this manually.
My app is using subscription items to show the user the current product they are subscribed to, by using something like subscription.items.first().price.product.name
. A workaround would be instead to use the deprecated plan
value, which does get synced correctly into the subscription, with something like Price.objects.get(id=subscription.plan.id).product.name
. The other alternative is my own webhook handler as well.
Software versions
- dj-stripe version: 2.4.3
- Python version: 3.9.5
- Django version: 3.1.4
- Stripe API version: 2.56.0
- Database type and version: Postgres 11.2
Can you reproduce the issue with the latest version of master? I haven’t had a chance to try yet, but I will in the next day or two.
Expected Behavior SubscriptionItems automatically syncing when a subscription is updated in Stripe.
Actual Behavior SubscriptionItems are not syncing at all automatically. I confirmed there were no errors via the webhookeventtrigger Django admin page.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
Thank you!
@vedran You were right.
SubscriptionItem
objects were not getting synced due to the exact reason you mentioned. I just raised a PR that should fix this issue: https://github.com/dj-stripe/dj-stripe/pull/1376