Skip to content

Encode bool and datetime list elements like top-level values - #1978

Open
alphasafal wants to merge 3 commits into
stripe:masterfrom
alphasafal:fix/encode-list-bool-datetime
Open

alphasafal wants to merge 3 commits into
stripe:masterfrom
alphasafal:fix/encode-list-bool-datetime

Conversation

@alphasafal

@alphasafal alphasafal commented Nov 12, 2026 •

Copy link
Copy Markdown

Why?

_api_encode converts bool values to "true"/"false" and datetime values to unix timestamps at the top level and inside nested dicts, but yields them unchanged when they are direct elements of a list. So {"flags": [True, False]} is sent as flags[0]=True&flags[1]=False, and {"created": [dt]} is sent as the datetime's str() form instead of a timestamp. Both form-encoded and multipart requests are affected, since both go through _api_encode.

What?

  • Handle datetime.datetime and bool in the list branch of _api_encode, mirroring the top-level handling.
  • Add two regression tests in tests/test_encode.py; both fail on master without the change and pass with it.
  • Add a .hark changefile.

See Also

Configuration

  • skip-changefile: This PR is not a user-facing change, so there's no changefile.

_api_encode converts top-level and nested-dict bool and datetime values
(bool -> "true"/"false", datetime -> unix timestamp) but yielded them
raw when they appeared as direct elements of a list. A list param therefore
serialized booleans as "True"/"False" and datetimes as their str() repr
instead of the forms the API expects. Handle bool and datetime in the list
branch the same way as at the top level. Adds regression tests.
@alphasafal
alphasafal requested a review from a team as a code owner November 12, 2026 05:01
@alphasafal
alphasafal requested review from mnorth-stripe and a balanced review from Copilot and removed request for a team November 12, 2026 05:01
@cla-assistant

cla-assistant Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Nov 12, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant

cla-assistant Bot commented Nov 12, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@jar-stripe jar-stripe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, thanks for the contribution!

@jar-stripe

Copy link
Copy Markdown
Contributor

Oh, just a heads up. After I approved I edited the "Fixes" out of your PR description. We leave issues open until after we release, and GitHub automation would have closed the ticket once this merges with that left in. Otherwise, looks good!

@alphasafal

Copy link
Copy Markdown
Author

Thanks for reviewing and approving this! I appreciate the clarification about keeping issues open until the fix is released. I'll follow that convention in future contributions. Thanks again!

This branch has not been deployed

No deployments
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