Unable to remove metadata from PaymentIntent.modify
navignaw opened this issue · 2 comments
Describe the bug
The Stripe docs indicate that you can unset metadata by passing empty values:
Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to metadata.
However, trying to do so by passing in None or an empty dict does nothing. When inspecting the outgoing request, it looks like the request drops the None values and treats them as "undefined" or unset.
To Reproduce
import stripe
# Create a payment intent and set metadata
pi = stripe.PaymentIntent.create(amount=2000, currency="usd")
stripe.PaymentIntent.modify(pi["id"], metadata={"foo": "bar"})
# Try to clear it
stripe.PaymentIntent.modify(pi["id"], metadata={"foo": None})
stripe.PaymentIntent.modify(pi["id"], metadata={})
stripe.PaymentIntent.modify(pi["id"], metadata=None)
Expected behavior
The payment intent's metadata should be cleared.
Actual behavior
The output payment intent still returns {"foo": "bar"}
in the metadata.
OS
macOS
Language version
Python 3.11
Library version
stripe-python 2.76.0
API version
2020-08-27
Additional context
No response
@navignaw This is expected behaviour today. The way to unset is to explicitly pass an empty string. Passing None will be ignored and the empty string is the only viable path.
You have to do this:
stripe.PaymentIntent.modify(pi["id"], metadata={"foo": ""})
stripe.PaymentIntent.modify(pi["id"], metadata="")
I'm going to close as I think the SDK works as expected here and it's not a bug.
Thanks for the update! I know it's outside the scope of this repo, but it might be worth clarifying this in the docs (e.g. "empty value" -> "empty string") in case anyone else who stumbles upon it gets confused.