Skip to content

Commit

Permalink
Fix handling of very large numbers in json. (#864)
Browse files Browse the repository at this point in the history
The fix was very easy: enable `arbitrary_precision` in JSON.

The issue was reported by a customer and manifested in a very annoying
and obscure manner.

Essentially what's going on: massive numbers in the schema (e.g.
-1.7976931348623157e+308) were being handled correctly when passed this
way, but not when passed as the full number with all of the 308 zeros
after it. This won't be a problem usually, as these numbers are wacky,
but there was a bug that was triggered with event type schemas. As
mentioned, we accept the `e+308` form, but rejected the full number with
all the zeros. The problem is that when saving schemas to postgres we
are saving it to a jsonb field which doesn't save the original json
structure. The field was saved without a problem (because of the short
representation), but once read from postgres, it was being read as the
long form, and our code was failing to parse that and just failing when
fetching this from database.
It seems like we aren't the first ones to hit this issue, and serde_json
already supports very large integers.

Here are the docs for this feature:
> Use an arbitrary precision number representation for
serde_json::Number. This
> allows JSON numbers of arbitrary size/precision to be read into a
Number and
> written back to a JSON string without loss of precision.

<!--
Thank you for your Pull Request. Please provide a description above and
review
the requirements below.

Bug fixes and new features should include tests.
-->

## Motivation

<!--
Explain the context and why you're making that change. What is the
problem
you're trying to solve? If a new feature is being added, describe the
intended
use case that feature fulfills.
-->

## Solution

<!--
Summarize the solution and provide any necessary context needed to
understand
the code change.
-->
  • Loading branch information
tasn authored Mar 6, 2023
1 parent cdfe1b7 commit 72c169d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion server/svix-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tokio = { version = "1.24.2", features = ["full"] }
tower = "0.4.11"
tower-http = { version = "0.3.4", features = ["trace", "cors", "request-id"] }
serde = { version = "1.0.133", features = ["derive"] }
serde_json = "1.0.74"
serde_json = { version = "1.0.74", features = ["arbitrary_precision"] }
serde_urlencoded = "0.7.1"
serde_path_to_error = "0.1.7"
num_enum = "0.5.6"
Expand Down

0 comments on commit 72c169d

Please sign in to comment.