Skip to content

Use rust_decimal's builtin PG encode/decode#989

Merged
sgrif merged 1 commit into
mainfrom
sg-builtin-decimal-serde
May 19, 2026
Merged

Use rust_decimal's builtin PG encode/decode#989
sgrif merged 1 commit into
mainfrom
sg-builtin-decimal-serde

Conversation

@sgrif
Copy link
Copy Markdown
Contributor

@sgrif sgrif commented May 19, 2026

We had enabled the feature on the rust_decimal crate to compile these functions, but were never actually using them. The postgres-types crate already existed as a transitive dependency of rust_decicmal, it's only added to our Cargo.toml so we can use the trait impls that decimal has.

Our tests for all the various malformed inputs were helpful here, the only one I think is excessive is rejecting NaN with digits. All the other cases caught places where the decimal crate hit unchecked overflow. It wouldn't have resulted in UB but the fact that it returns nonsense instead of an error is something that's good for us to catch.

This does slightly change our behavior, as their encoding implementation fails to remove leading zeroes from the output when the result is an exact power of 10000. This shouldn't matter, as the two values are completely equivalent as far as PG is concerned (and I've verified as such manually). I've updated the test case to reflect this behavior, though I think if we accept this change we should probably just delete it since we're testing a crate's behavior and not our own.

We had enabled the feature on the rust_decimal crate to compile these
functions, but were never actually using them. The postgres-types crate
already existed as a transitive dependency of rust_decicmal, it's only
added to our Cargo.toml so we can use the trait impls that decimal has.

Our tests for all the various malformed inputs were helpful here, the
only one I think is excessive is rejecting NaN with digits. All the
other cases caught places where the decimal crate hit unchecked
overflow. It wouldn't have resulted in UB but the fact that it returns
nonsense instead of an error is something that's good for us to catch.

This does slightly change our behavior, as their encoding implementation
fails to remove leading zeroes from the output when the result is an
exact power of 10000. This shouldn't matter, as the two values are
completely equivalent as far as PG is concerned (and I've verified as
such manually). I've updated the test case to reflect this behavior,
though I think if we accept this change we should probably just delete
it since we're testing a crate's behavior and not our own.
@sgrif sgrif requested a review from levkk May 19, 2026 21:58
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 19, 2026

CLA assistant check
All committers have signed the CLA.

@sgrif
Copy link
Copy Markdown
Contributor Author

sgrif commented May 19, 2026

@CLAassistant You can't take my rights you don't even have a soul

Copy link
Copy Markdown
Collaborator

@levkk levkk left a comment

Choose a reason for hiding this comment

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

Image Image

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sgrif sgrif merged commit 5f9c7cb into main May 19, 2026
21 of 22 checks passed
@sgrif sgrif deleted the sg-builtin-decimal-serde branch May 19, 2026 22:16
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