Skip to content

fix(mysql): don't infer u8 for YEAR columns - #4481

Open
flawand wants to merge 3 commits into
transact-rs:mainfrom
flawand:bug/mysql-year-type-inference
Open

flawand wants to merge 3 commits into
transact-rs:mainfrom
flawand:bug/mysql-year-type-inference

Conversation

@flawand

@flawand flawand commented Oct 23, 2026

Copy link
Copy Markdown

Does your PR solve an issue?

Yes, fixes #4358.

The issue is closed, but the bug is still reproducible on main. The first commit adds an integration test that fails with "out of range integral type conversion attempted", and the second commit fixes it.

Is this a breaking change?

No. Macros query!/query_as! now infer u16 for YEAR columns instead of u8, which only affects code that was already failing at runtime for any year in 1901-2155.

fadilawand added 3 commits October 22, 2026 23:34
The query!/query_as! macros infer `u8` for MySQL `YEAR` columns. Valid values (1901..=2155) don't fit in 8 bits, so decoding fails with "out of range integral type conversion attempted".

This test currently fails; it is fixed in a follow-up commit.
`YEAR` values (1901-2155) don't fit in `u8`, but `uint_compatible` accepted `YEAR` for every unsigned integer type, so the query!/query_as! macros inferred `u8` and decoding failed.

Add `uint_compatible_nonu8`, which still accepts `YEAR`, and use it for the integer types wide enough to hold it, so inference falls through to `u16`.

Fixes transact-rs#4358
The `users` table added to setup.sql collided with `issue_3200`, which runs `CREATE TABLE IF NOT EXISTS users` with a different schema, so that test failed with "Unknown column 'username'" in CI.

Rename the table to `query_as_year_inference` and run `cargo fmt` to fix the Format check.
@flawand

flawand commented Oct 24, 2026

Copy link
Copy Markdown
Author

@abonander please review my PR. Note this PR was created as result of closing #4447 due to failing the AI policy that was recently codified.

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.

Runtime decoding error when mapping MariaDB YEAR/SMALLINT to u16 using query_as!

1 participant