Repository navigation
fix(sqlite): return an error instead of panicking when decoding an out-of-range INTEGER as PrimitiveDateTime - #4433
Open
breken-ai wants to merge 1 commit into
Conversation
…EGER PrimitiveDateTime Decoding `time::PrimitiveDateTime` from an INTEGER column called `OffsetDateTime::from_unix_timestamp(..).unwrap()`, so any value outside `time`'s range (e.g. a millisecond Unix timestamp such as 1700000000000) panicked while decoding the row. `OffsetDateTime` and the chrono types already return an error here; do the same.
abonander
requested changes
Oct 3, 2026
abonander
left a comment
Collaborator
There was a problem hiding this comment.
If you rebase it should fix the CI failure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Does your PR solve an issue?
No open issue.
Decoding
time::PrimitiveDateTimefrom an SQLiteINTEGERvalue panics if the value is outsidetime's range. A common case is a millisecond Unix timestamp, e.g. a column filled from JavaScript'sDate.now():The integer branch of
decode_datetimecallsOffsetDateTime::from_unix_timestamp(..).unwrap(). It has done this since at least 0.7.0. The same file'sOffsetDateTimedecode uses?there, and the chrono impls returnNone, which becomes a decode error. So onlyPrimitiveDateTimetakes down the calling task instead of returning anErrthe application can handle.The fix replaces
.unwrap()with?. It adds a regression test totests/sqlite/types.rs(it_errors_on_out_of_range_integer_primitive_date_time).DATABASE_URL=sqlite://tests/sqlite/sqlite.db cargo test --no-default-features --features sqlite,runtime-tokio,time,macros,migrate --test sqlite-typespanics in the new test.cargo test -p sqlx-sqlite --all-featurespasses,cargo fmt --checkis clean, and clippy shows no new warnings insqlx-sqlite.I used an AI assistant (Claude) to help find and write this fix. I reviewed the change and ran the tests above myself.
Is this a breaking change?
No. A value that used to panic now returns a decode error. Values in range decode the same as before.