Repository navigation
Conversation
`YEAR`'s value domain is `0` or `1901..=2155`, which doesn't fit in `u8`. `uint_compatible()` treated `YEAR` as compatible with every unsigned integer type, so the macros' default type inference (which scans types in declaration order and picks the first match) always picked `u8`, causing a runtime decode error for any realistic year value. `u8` is now excluded, so inference falls through to `u16`, `u32`, or `u64`. Fixes transact-rs#4358 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The test added in the previous commit needs this table to exist in the database *before* compilation, since query!/query_as! introspect live schema at compile time. It was missing from tests/mysql/setup.sql, so CI's fresh database didn't have it and the macro failed with "Table 'sqlx.macro_infer_year_type' doesn't exist". Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
YEAR's value domain is0or1901..=2155, which doesn't fit inu8.uint_compatible()insqlx-mysql/src/types/uint.rstreatedColumnType::Yearas compatible with every unsigned integer type (u8,u16,u32,u64), and since thequery!/query_as!macros infer a default Rust type by scanning the declared type list in order and picking the firstcompatible()match,u8(listed first) always won — causing a runtime decode error (out of range integral type conversion attempted) for any realistic year value.u8is now excluded from matchingYEARcolumns via a newuint_non_year_compatible()check, so default inference falls through tou16(the next candidate, and the smallest type that can hold the fullYEARrange). As a side effect, an explicit: u8override on aYEARcolumn is now also a compile-time error instead of a silent runtime failure.Fixes #4358
Test plan
macro_infer_year_typetotests/mysql/macros.rs, reproducing the issue against a live MariaDB 11.8 instance: before the fix it failed with the exact error from the issue (out of range integral type conversion attempted); after the fix it passes and prints the correctly-decoded year.cargo check -p sqlx-mysqlpasses.