Repository navigation
Refuse values that do not fit their database column - #2568
Conversation
|
@cdk-bot review |
|
Could we retain the public Moving the SQL persistence paths to checked This seems especially worth preserving because the split-out direction discussed on #2473 explicitly called for retaining the public Unless removing these helpers is an intentional breaking API change, keeping them and their boundary tests would preserve downstream compatibility without affecting the database fix. |
c7a7d64 to
08e5f8a
Compare
|
@cdk-bot review |
cdk-bot
left a comment
There was a problem hiding this comment.
Verified findings approved for disclosure:
- Wallet mint_quote reads now hard-fail on legacy negative amounts instead of returning amount: None (low) - see inline comment
|
@cdk-bot review |
j-kon
left a comment
There was a problem hiding this comment.
Findings
- No critical, warning, or nit-level issues found.
- The migration safely widens integer columns to
BIGINTfor Postgres without altering immutable past migrations. - Replacing implicit truncations with checked
try_fromconversions ensures out-of-range database writes fail fast at the persistence layer rather than silently corrupting state. - Commit
08e5f8a4properly restored the publicAmount::to_i64andAmount::from_i64helpers along with thorough boundary unit tests, preserving API stability.
- The migration safely widens integer columns to
Summary
Reviewed database widening migrations, SQL parameter bindings, checked numeric conversions in cdk-sql-common and cdk-postgres, and the restored public Amount helpers. The changes prevent silent data truncation and keep public API backwards-compatible.
Verdict
APPROVE
thesimplekid
left a comment
There was a problem hiding this comment.
One of the things that give me most pause about the other PR is the database migration so the motivation of this PR was to avoid that and just error on anything we cannot store instead of silently wrapping and leave a migration to a follow up.
08e5f8a to
ea8720a
Compare
|
@cdk-bot review |
Use checked integer conversions when binding SQL values so out-of-range values return an error instead of being truncated or stored as NULL. Preserve NULL for absent optional values. Check PostgreSQL INT2 and INT4 bounds and decode INT2 values as i16. Keep existing column widths; widening columns and supporting the full u64 amount range remain separate work.
ea8720a to
4089d6c
Compare
Description
This is a simpler solution for #2425 before #2473 is matured.
Every integer column is signed, and the bind path narrowed with an unchecked cast, so a value past the signed maximum wrapped to a negative value and was committed, while Amount::to_i64 erased an oversized amount into NULL. Narrowing is checked now and refuses the write instead.
Postgres declared most of those columns int4 and truncated silently, storing an expiry past 2038 as a date already gone, so we widened them to int8. The balance query casts its aggregate back because a wider sum returns numeric. Storing amounts at their full u64 width stays a separate change.
Notes to the reviewers
Suggested CHANGELOG Updates
CHANGED
ADDED
REMOVED
FIXED
Checklist
just quick-checkbefore committingcrates/cdk-ffi)