sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

the trait bound bool: std::convert::From<std::option::Option<bool>> is not satisfied

Open FrenchGithubUser opened this issue 3 months ago • 4 comments

I have found these related issues/pull requests

None

Description

         let rows = sqlx::query_as!(
            DBImportTorrent,
            r#"
            SELECT
                id,
                upload_factor,
                download_factor,
                seeders,
                leechers,
                times_completed,
                CASE
                    WHEN deleted_at IS NOT NULL THEN TRUE
                    ELSE FALSE
                END AS is_deleted
            FROM torrents
            "#
        )


#[derive(Debug)]
pub struct DBImportTorrent {
    pub id: i32,
    pub upload_factor: f64,
    pub download_factor: f64,
    pub seeders: i64,
    pub leechers: i64,
    pub times_completed: i32,
    pub is_deleted: bool,
} 

Throws this error: the trait bound bool: std::convert::From<std::option::Option<bool>> is not satisfied

Reproduction steps

Run the code above

SQLx version

0.8

Enabled SQLx features

"runtime-tokio", "tls-native-tls", "postgres", "chrono", "ipnetwork"

Database server and version

Postgres

Operating system

Asahi linux

Rust version

1.89.0

FrenchGithubUser avatar Oct 18 '25 09:10 FrenchGithubUser

You can override the macro's, see https://docs.rs/sqlx/latest/sqlx/macro.query.html#type-overrides-output-columns.

Which boils down to changing the as is_deleted part of the query to as "is_deleted!".

joeydewaal avatar Oct 18 '25 10:10 joeydewaal

that works indeed, but will it keep checking for type safety then ?

FrenchGithubUser avatar Oct 20 '25 12:10 FrenchGithubUser

No, the is_deleted field's type is overridden, so you're opting out of typechecking. The other fields however are still checked.

joeydewaal avatar Oct 22 '25 21:10 joeydewaal

No, the is_deleted field's type is overridden, so you're opting out of typechecking.

Okay, so there is actually a bug in the situation I pointed out ? It's not blocking, but still a bug

FrenchGithubUser avatar Oct 23 '25 18:10 FrenchGithubUser