Skip to content

fix(macros): only report Ambiguous{DateTime,Numeric}Type when preferred crate is Inferred - #4463

Merged
abonander merged 1 commit into
transact-rs:mainfrom
sandbanks:fix/preferred-crates-inferred-check
Oct 15, 2026
Merged

abonander merged 1 commit into
transact-rs:mainfrom
sandbanks:fix/preferred-crates-inferred-check

Conversation

@rscorer

@rscorer rscorer commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Problem

When either both chrono and time, or bigdecimal and rust_decimal features are active in the build graph, setting an explicit preferred crate in sqlx.toml still causes query!() macros to emit warnings warn_on_ambiguous_inferred_date_time_crate / warn_on_ambiguous_inferred_numeric_crate.

Analysis

In sqlx-core/src/type_checking.rs, the branches for DateTimeCrate::Time and NumericCrate::BigDecimal check:

#[cfg(feature = "time")]
if matches!(preferred_crates.date_time, DateTimeCrate::Time | DateTimeCrate::Inferred) {
    ...
    if cfg!(feature = "chrono") {
        return Err(Error::AmbiguousDateTimeType { ... });
    }
}

Because cfg!(feature = "chrono") was checked unconditionally inside the matches!(..., Time | Inferred) block, setting date-time = "time" still returned AmbiguousDateTimeType.

The same issue affected param_type_for_id and return_type_for_id for both DateTimeCrate::Time and NumericCrate::BigDecimal.

Solution

Only return AmbiguousDateTimeType / AmbiguousNumericType if preferred_crates.{date_time,numeric} is Inferred:

 if preferred_crates.date_time == DateTimeCrate::Inferred && cfg!(feature = "chrono")

and

if preferred_crates.numeric == NumericCrate::Inferred && cfg!(feature = "rust_decimal")

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.

…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.
@abonander
abonander merged commit 39eff06 into transact-rs:main Oct 15, 2026
147 checks passed
@rscorer
rscorer deleted the fix/preferred-crates-inferred-check branch October 15, 2026 22:39
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.

2 participants