⚡ Solution Summary

  • Nested APIResource values are skipped during serialization.
  • Workaround: Use ID references instead of objects.
  • No fix planned due to deprecated functionality.
### Describe the bug When serializing any stripe.StripeObject, nested stripe.APIResource values are silently skipped due to a continue branch in serialize()... This results in incomplete payloads sent to the Stripe API with no errors or warnings, causing data integrity issues and production failures... This happens inside stripe/_stripe_object.py (elif isinstance(v, stripe.APIResource): continue). ### To Reproduce 1- Create a stripe.Customer() and a nested stripe.PaymentMethod() with an id. 2- Assign the nested resource to the customer and call serialize(). 3- Observe the nested field is missing from the serialized output... ### Expected behavior - Nested APIResource values should not be dropped. - The bare minimum here is to serialize them as ID references or just an object reference when an ID is not available... ### Code snippets ```Python # stripe/_stripe_object.py elif isinstance(v, stripe.APIResource): continue # Silently drops nested APIResource objects ``` ### OS all ### Language version python 3.13.7 ### Library version latest ### API version 2025-08-27.basil ### Additional context _No response_

Discussion & Fixes

jar-stripe 2025-08-29
Hi @geminimir , thank you for reporting this and I am sorry for the trouble this is causing! I will investigate this right away. Is this something that you are only seeing in the most recently released version? Or have you seen this behavior in older versions as well?
jar-stripe 2025-08-29
Ok, did a little digging and a little thinking and I have some questions. First, to make sure I'm on the right track on understanding your issue, here's my test: ``` import stripe customer = stripe.Customer() customer.balance = 1000 payment_method = stripe.PaymentMethod(id="pm_123") customer.invoice_credit_balance = { 'USD': 500 } customer.invoice_settings = stripe.Customer.InvoiceSettings() customer.invoice_settings.default_payment_method = payment_method serialized_customer = customer.serialize(None) print(serialized_customer) ``` And that prints out: `{'balance': 1000, 'invoice_credit_balance': {'USD': 500}}` Is that what you're seeing? Taking a step back, can you share a bit more about what you're trying to do with serializing StripeObject types?
geminimir 2025-08-30
Yes that's the issue we're seeing... We first hit this because our production code was doing what felt natural... ``` customer.default_payment_method = payment_method_object customer.save() ``` but the payment method updates were silently failing... took us a while to figure out that serialize() just skips APIResource objects entirely... The workaround seems to be just using IDs, but that's not intuitive... Would be great if serialize() could just extract the ID from APIResource objects automatically... Happy to provide more examples or help test a fix if useful...
mbroshi-stripe 2025-09-02
Thanks again for bringing up this issue! Unfortunately, we cannot address it because 1. The `save` functionality is already deprecated, and 2. Other users may be depending on its current behavior, so we don't want to break their integrations. It sounds like you have a workaround for your use case, so I'm going to close out this issue.

Get updates

We publish verified fixes weekly. No spam.

Subscribe