Repository navigation
fix(macros): only report Ambiguous{DateTime,Numeric}Type when preferred crate is Inferred - #4463
Merged
abonander merged 1 commit intoOct 15, 2026
Conversation
…ed crate is Inferred
When both `chrono` and `time` (or `bigdecimal` and `rust_decimal`) are enabled in the dependency tree, setting an explicit preferred crate in `sqlx.toml` (e.g. `[macros.preferred-crates] date-time = "time"`) still returned an `AmbiguousDateTimeType` error because the macro unconditionally checked `if cfg!(feature = "chrono")`.
This fix ensures `AmbiguousDateTimeType` and `AmbiguousNumericType` are only returned when `preferred_crates.{date_time,numeric}` is `Inferred`, and adds unit tests covering the fix.
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.
Problem
When either both
chronoandtime, orbigdecimalandrust_decimalfeatures are active in the build graph, setting an explicit preferred crate insqlx.tomlstill causesquery!()macros to emit warningswarn_on_ambiguous_inferred_date_time_crate/warn_on_ambiguous_inferred_numeric_crate.Analysis
In
sqlx-core/src/type_checking.rs, the branches forDateTimeCrate::TimeandNumericCrate::BigDecimalcheck:Because
cfg!(feature = "chrono")was checked unconditionally inside thematches!(..., Time | Inferred)block, settingdate-time = "time"still returnedAmbiguousDateTimeType.The same issue affected param_type_for_id and return_type_for_id for both
DateTimeCrate::TimeandNumericCrate::BigDecimal.Solution
Only return AmbiguousDateTimeType / AmbiguousNumericType if preferred_crates.{date_time,numeric} is Inferred:
and
Unit tests have been added in sqlx-postgres verifying that explicit crate selections succeed when both conflicting crate features are enabled in the build graph.