Skip to content

Add runtime support for V2 int64 string-encoded fields#1756

Merged
mbroshi-stripe merged 6 commits intomasterfrom
mbroshi/v2-int64-as-string
Mar 18, 2026
Merged

Add runtime support for V2 int64 string-encoded fields#1756
mbroshi-stripe merged 6 commits intomasterfrom
mbroshi/v2-int64-as-string

Conversation

@mbroshi-stripe
Copy link
Contributor

@mbroshi-stripe mbroshi-stripe commented Mar 12, 2026

Why?

V2 APIs represent int64 fields as JSON strings on the wire (e.g. "12345" instead of 12345) to avoid precision loss. The SDK should transparently convert between native Python int and this wire format so users don't need to handle string encoding themselves.

What?

  • Added _coerce_v2_params() and _coerce_value() to stripe/_encode.py for request-side coercion (int → str), handling scalars, nested objects, and arrays
  • Added _field_encodings class variable and _coerce_field_value() method to StripeObject for response-side coercion (str → int) during _refresh_from
  • Added tests covering top-level, nested, array, nullable, and mixed-field scenarios for both request and response paths

@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/v2-int64-as-string branch from d8449b2 to 054338e Compare March 15, 2026 18:45
@mbroshi-stripe mbroshi-stripe changed the base branch from master to private-preview March 15, 2026 19:44
@mbroshi-stripe mbroshi-stripe changed the title WIP Mbroshi/v2 int64 as string Mar 15, 2026
@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/v2-int64-as-string branch from 3176f76 to cb5ea24 Compare March 15, 2026 22:03
@mbroshi-stripe mbroshi-stripe changed the title Mbroshi/v2 int64 as string Add runtime support for V2 int64 string-encoded fields Mar 15, 2026
@mbroshi-stripe mbroshi-stripe changed the base branch from private-preview to master March 15, 2026 22:32
@mbroshi-stripe mbroshi-stripe marked this pull request as ready for review March 16, 2026 00:47
@mbroshi-stripe mbroshi-stripe requested a review from a team as a code owner March 16, 2026 00:47
@mbroshi-stripe mbroshi-stripe requested review from prathmesh-stripe and removed request for a team March 16, 2026 00:47
Copy link
Member

@xavdid-stripe xavdid-stripe left a comment

Choose a reason for hiding this comment

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

This makes sense, but will likely conflict with #1762 (at a git and/or logical level). Also I don't think your fancier function actually gets used, so either it's not needed or should be wired up (or I misread)

@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/v2-int64-as-string branch from a7510c6 to 285c24a Compare March 18, 2026 01:09
Copy link

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

Adds runtime coercion for V2 int64_string fields so SDK users can work with native Python int values while V2 JSON wire format uses strings.

Changes:

  • Introduces request-side param coercion in stripe/_encode.py via _coerce_v2_params() / _coerce_value() and a shared helper _coerce_int64_string().
  • Adds response-side field coercion to StripeObject._refresh_from() via _field_encodings + _coerce_field_value().
  • Adds a dedicated test suite covering request/response coercion scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
stripe/_encode.py Implements request coercion and shared int64_string conversion helper.
stripe/_stripe_service.py Wires request coercion into service request paths via _param_encodings.
stripe/_stripe_object.py Adds response hydration coercion via _field_encodings in _refresh_from.
tests/test_int64_string.py Adds unit tests for both request serialization and response hydration coercion.

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

@mbroshi-stripe mbroshi-stripe merged commit 48c6471 into master Mar 18, 2026
20 checks passed
@mbroshi-stripe mbroshi-stripe deleted the mbroshi/v2-int64-as-string branch March 18, 2026 15:54
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