stripe-python icon indicating copy to clipboard operation
stripe-python copied to clipboard

Fix DeprecationWarning when encoding StripeObject metadata (fixes #1651)

Open praniketkw opened this issue 1 month ago • 0 comments

Fixes #1651

Why?

When updating metadata on resources like invoices, users encountered a DeprecationWarning even though they were using the public API correctly. The warning was triggered internally when the encoder checked for the deprecated stripe_id property on StripeObject instances.

What?

  • Changed the encoding logic in stripe/_encode.py to avoid triggering the deprecated stripe_id property
  • Modified _api_encode function to check for objects with an id field using value.get("id") instead of accessing value.stripe_id
  • The new check verifies the value has a callable get method and uses it to safely access the id field without triggering property decorators
  • Preserved all existing encoding behavior where objects with an id encode to just their id value and objects without an id expand as nested dictionaries
  • Added comprehensive test suite in tests/test_encode.py covering StripeObjects with and without ids, regular dicts, lists, booleans, None values, and edge cases

praniketkw avatar Nov 25 '25 18:11 praniketkw