Skip to content

Fix 2D array parameter encoding#1786

Merged
jar-stripe merged 4 commits intomasterfrom
jar/fix-2d-array-encoding
Apr 1, 2026
Merged

Fix 2D array parameter encoding#1786
jar-stripe merged 4 commits intomasterfrom
jar/fix-2d-array-encoding

Conversation

@jar-stripe
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe commented Apr 1, 2026

Why?

When encoding nested lists (e.g. [[1, 2], [3, 4]]) as form parameters, there was no code path to handle list elements that are themselves lists. They fell through to the else branch and were stringified as raw Python list objects, producing items[0]=[1, 2] instead of the correct items[0][0]=1&items[0][1]=2.

What?

  • Add elif isinstance(sv, (list, tuple)) branch in stripe/_encode.py that recurses via _encode_nested_dict
  • Add regression test for nested list encoding in tests/test_encode.py

See Also

Changelog

  • Fixes an issue encoding two-dimensional array request params where the SDK incorrectly flattens the array.

When encoding nested lists (e.g. [[1, 2], [3, 4]]), there was no code
path to handle list elements that are themselves lists. They fell through
to the else branch and were stringified as raw Python list objects,
producing `items[0]=[1, 2]` instead of `items[0][0]=1&items[0][1]=2`.

Fix by adding a recursive branch for list/tuple elements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
@jar-stripe jar-stripe marked this pull request as ready for review April 1, 2026 04:04
@jar-stripe jar-stripe requested a review from a team as a code owner April 1, 2026 04:04
@jar-stripe jar-stripe requested review from Copilot and mbroshi-stripe and removed request for a team April 1, 2026 04:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes form-parameter encoding for nested lists (2D arrays) so list elements that are themselves lists/tuples are recursively encoded with indexed keys instead of being stringified as raw Python lists.

Changes:

  • Add nested list/tuple handling in _api_encode to recurse via _encode_nested_dict using enumerated indices.
  • Add a regression test asserting correct items[0][0]-style encoding for 2D arrays.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
stripe/_encode.py Adds an elif isinstance(sv, (list, tuple)) branch to properly encode nested arrays with double indices.
tests/test_encode.py Adds regression coverage for nested list encoding output ordering and key format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jar-stripe jar-stripe enabled auto-merge (squash) April 1, 2026 17:03
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
Copy link
Copy Markdown
Contributor

@prathmesh-stripe prathmesh-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need formatting but looks good

@jar-stripe jar-stripe merged commit f6b17f7 into master Apr 1, 2026
16 checks passed
@jar-stripe jar-stripe deleted the jar/fix-2d-array-encoding branch April 1, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants