fix: encode empty list/tuple as (key, '') to clear array fields#1817
Open
devteamaegis wants to merge 1 commit into
Open
fix: encode empty list/tuple as (key, '') to clear array fields#1817devteamaegis wants to merge 1 commit into
devteamaegis 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. |
1 similar comment
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.