Skip to content
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

StripeBaseModel.sync_from_stripe_data only persists data if its a new instance, but won't update an existing instance #2032

Open
MattTheRed opened this issue Mar 11, 2024 · 0 comments
Labels

Comments

@MattTheRed
Copy link

MattTheRed commented Mar 11, 2024

Describe the bug
StripeBaseModel.sync_from_stripe_data seems to be to intended for synchronously updating a given DJ stripe model in the database from a Stripe API response (VS relying on the webhooks to asyncronously update the database).

To Reproduce

This looks to be working fine if you use this method for a brand new model instance (since a get_or_create_from_stripe_object is used), but does not persist changes if you are updating an existing instance.

# invoice is persisted to the database if a brand new object is created
invoice_obj = Invoice._api_create(...)
invoice = Invoice.sync_from_stripe_data(invoice_obj)

# updated to paid_invoice are NOT persisted to the database
paid_invoice_obj = invoice.api_retrieve().pay()
paid_invoice = Invoice.sync_from_stripe_data(paid_invoice_obj)

# This will persist the changes
paid_invoice.save()

I believe if you add an instance.save() call here that will fix things.

Software versions

  • Dj-Stripe version:
  • Python version:
  • Django version:
  • Stripe API version:
  • Database type and version:
@MattTheRed MattTheRed added the bug label Mar 11, 2024
@MattTheRed MattTheRed changed the title Invoice.sync_from_stripe_data only persists data if its a new instance StripeBaseModel.sync_from_stripe_data only persists data if its a new instance Mar 11, 2024
@MattTheRed MattTheRed changed the title StripeBaseModel.sync_from_stripe_data only persists data if its a new instance StripeBaseModel.sync_from_stripe_data only persists data if its a new instance, but won't update an existing instance Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant