Visitar URL original
fix(wkt): accept arbitrary_precision numbers in float fields by josh-brown-anchor · Pull Request #6991 · googleapis/google-cloud-rust · GitHub
Skip to content

fix(wkt): accept arbitrary_precision numbers in float fields - #6991

Open
josh-brown-anchor wants to merge 1 commit into
googleapis:mainfrom
josh-brown-anchor:fix-wkt-float-arbitrary-precision
Open

josh-brown-anchor wants to merge 1 commit into
googleapis:mainfrom
josh-brown-anchor:fix-wkt-float-arbitrary-precision

Conversation

@josh-brown-anchor

Copy link
Copy Markdown

Fixes #6990

With serde_json's arbitrary_precision feature enabled anywhere in the dependency graph, serde_json hands non-integer numbers to deserialize_any as a single-entry map. The ProtoJSON float visitors rejected that map, so any fractional float/double field failed with invalid type: map, expected a 32-bit float in ProtoJSON format.

This adds visit_map to the visitors in visitor_float.rs, decoding the map through serde_json::Number and reusing the visit_f64 range check. Without the feature, serde_json::Number rejects the map, so behavior is unchanged.

The new tests parse from JSON text (serde_json::Deserializer::from_str / from_str), the path the feature changes; the existing tests use from_value, which is unaffected. They pass with and without --features serde_json/arbitrary_precision, and fail without the fix when the feature is on.

With serde_json's `arbitrary_precision` feature enabled anywhere in the
dependency graph, serde_json hands non-integer numbers to
`deserialize_any` as a single-entry map. The ProtoJSON float visitors
rejected that map, so any fractional `float`/`double` field failed to
parse. Decode the map through `serde_json::Number`.
@josh-brown-anchor
josh-brown-anchor requested a review from a team as a code owner September 25, 2026 14:11
@google-cla

google-cla Bot commented Sep 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds support for deserializing float values (both f32 and f64) when serde_json's arbitrary_precision feature is enabled. This is achieved by implementing visit_map in the float visitor macro to handle the single-entry map representation of numbers, using serde_json::Number and MapAccessDeserializer. Additionally, comprehensive unit and integration tests have been added to verify correct deserialization and error handling from JSON text. I have no feedback to provide.

@dbolduc

dbolduc commented Sep 25, 2026

Copy link
Copy Markdown
Member

/gcbrun

@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.07%. Comparing base (46a5e25) to head (a81240b).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/wkt/src/internal/visitor_float.rs 45.45% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6991      +/-   ##
==========================================
- Coverage   97.07%   97.07%   -0.01%     
==========================================
  Files         326      326              
  Lines      113032   113065      +33     
==========================================
+ Hits       109730   109758      +28     
- Misses       3302     3307       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suzmue suzmue 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.

Thanks for investigating and contributing this fix, LGTM!

I tested this locally on main with --features serde_json/arbitrary_precision and confirmed that direct JSON text deserialization of non-integer floats indeed failed with invalid type: map, expected a 32-bit float in ProtoJSON format when the feature was enabled.

Possible future improvement: we should consider additional integration tests with different feature combos for this crate.

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.

wkt: float/double fields fail to deserialize when serde_json's arbitrary_precision feature is enabled

3 participants