Skip to content

Conversation

@praniketkw
Copy link
Contributor

@praniketkw praniketkw commented Nov 25, 2025

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. While the deprecation warning serves an important purpose for direct user access to stripe_id, it should not be shown for internal library usage.

What?

  • Modified the _api_encode function in stripe/_encode.py to suppress DeprecationWarning when internally accessing the stripe_id property.
  • Added warnings.catch_warnings() context managers around both the hasattr check and the property access to prevent warnings from bubbling up to users during internal encoding operations.
  • Preserved the deprecation warning for direct user access to stripe_id while silencing it only for internal library usage.
  • Updated tests to verify that no deprecation warnings are raised during encoding operations while maintaining all existing encoding behavior.
  • The approach maintains the intended deprecation strategy while fixing the user experience issue where legitimate API usage triggered internal warnings.

@praniketkw praniketkw requested a review from a team as a code owner November 25, 2025 18:42
@praniketkw praniketkw requested review from xavdid-stripe and removed request for a team November 25, 2025 18:42
@ramya-stripe ramya-stripe requested review from prathmesh-stripe and removed request for xavdid-stripe December 2, 2025 03:02
@ramya-stripe ramya-stripe requested review from ramya-stripe and removed request for prathmesh-stripe December 9, 2025 18:21
@ramya-stripe
Copy link
Contributor

@praniketkw Can you also update the PR description based on the new approach?

@praniketkw
Copy link
Contributor Author

@ramya-stripe Done!

if value is None:
continue
elif hasattr(value, "stripe_id"):
yield (key, value.stripe_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @praniketkw

Just thought of an alternative with a smaller footprint. Can you try this and see if it works?

elif hasattr(value, "stripe_id")
   yield (key, getattr(value, "id"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct update metadata causes DeprecationWarning

2 participants