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

Direct update metadata causes DeprecationWarning

Open sshishov opened this issue 2 months ago • 2 comments

Describe the bug

Our code is trying to update the metadata (without casting/converting to the dict). When we are modify the instance, the data is getting encoded using the internal sources and causes DeprecationWarning when it tries to check for stripe_id attribute on the object.

Because this is internal usage, the warning should not be raised.

To Reproduce

  1. Fetch an invoice with metadata filled
  2. Get the metadata directly
  3. Update metadata
  4. Update the invoice with new metadata
  5. Observe the DeprecationWarning
args = (<StripeObject at 0xffff6827fcf0> JSON: {
  "newkey": "value",
},), kwargs = {}

    @functools.wraps(__arg)
    def wrapper(*args, **kwargs):
>       warnings.warn(
            __msg, category=category, stacklevel=stacklevel + 1
        )
E       DeprecationWarning: For internal stripe-python use only. The public interface will be removed in a future version.

Expected behavior

There should not be validation error happening while updating metadata

NOTE: the issue can be "silenced" by forcely casting the metadata to dict as it will not be StripeObject anymore and will not cause DeprecationWarning during encoding...

Code snippets

invoice = stripe.Invoice.retrieve(...)
metadata = invoice.metadata or {}
metadata['newkey'] = 'value'
stripe.Invoice.modify(invoice.id, metadata=metadata)

OS

Linux

Language version

Python 3.13

Library version

stripe-python v11.6.0

API version

2017-08-15

Additional context

We are using slightly obsolete versions... but I have checked main, the code for encode.py is the same and the check for attr stripe_id is there. I am pretty sure the same issue should happen on the latest versions.

sshishov avatar Oct 22 '25 11:10 sshishov

Thanks for flagging! We'll take a look to see if we can avoid emitting the warning in this case.

xavdid-stripe avatar Oct 27 '25 21:10 xavdid-stripe

Hello @ramya-stripe ! I have tried fixing this issue. Please review my latest PR #1687

praniketkw avatar Nov 25 '25 18:11 praniketkw