Skip to content

Direct update metadata causes DeprecationWarning #1651

@sshishov

Description

@sshishov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions