fix: encode empty list/tuple as (key, '') to clear array fields#1817
fix: encode empty list/tuple as (key, '') to clear array fields#1817devteamaegis wants to merge 1 commit into
Conversation
When a list or tuple field is set to [] or () in a Stripe API modify/update call, _api_encode yielded nothing — the field was omitted from the request entirely, so the Stripe API left previously-set values unchanged. The documented workaround was to pass "" (empty string) instead of [], which encodes to (key, "") and signals to the API to clear the field. This fix makes an empty list (or tuple) behave identically to the empty-string workaround: it emits (key, "") before the indexed loop so that a previously-set array field is cleared rather than silently left as-is. Fixes stripe#802
|
|
|
Ishaan Samantray seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Hi @devteamaegis , thank you for the PR! This fix seems reasonable and we are reviewing. In the mean time we need you to sign our CLA for us to be able to merge it in; can you take a look at that please? |
4cb4a49 to
bf8ecb2
Compare
|
Unfortunately, we are unable to merge PRs from contributors that have not signed our CLA. Closing. |
Problem
Passing an empty
listortuplefor an array field in a Stripe API update call silently does nothing — the field is omitted from the request body and the previously-set values remain unchanged.Reproduction:
The documented workaround is to pass
""instead of[]:This is because
_api_encodeiterates over the list withenumerate, and an empty list yields zero iterations — no key/value pair is emitted and the field disappears from the request.Fixes #802.
Fix
Before the indexed loop in
_api_encode, detect an empty list/tuple and emit(key, "")— the same encoding produced by the""workaround — so the Stripe API receives an explicit signal to clear the field:Tests
Two new assertions in
tests/test_encode.py:test_encode_empty_list_yields_empty_string[]→[("blocked_categories", "")]test_encode_empty_tuple_yields_empty_string()→[("tags", "")]Both pass; existing list-encoding tests are unchanged.