SeaQL/sea-orm · error

Failed to get boolean

Error message

Failed to get boolean

What it means

In `from_sqlx_mysql_row_to_proxy_row`, a column whose sqlx type info is "TINYINT(1)" or "BOOLEAN" is decoded with `row.try_get::<bool>` and `.expect("Failed to get boolean")`. The panic fires when sqlx cannot decode the cell value as a bool — most often because the value is NULL but the code requests a non-Option bool, or the underlying type/decode mismatch. This happens in the `proxy` feature when converting raw MySqlRows into ProxyRow.

Source

Thrown at sea-orm-sync/src/driver/sqlx_mysql.rs:389

    }
}

#[cfg(feature = "proxy")]
pub(crate) fn from_sqlx_mysql_row_to_proxy_row(row: &sqlx::mysql::MySqlRow) -> crate::ProxyRow {
    // https://docs.rs/sqlx-mysql/0.7.2/src/sqlx_mysql/protocol/text/column.rs.html
    // https://docs.rs/sqlx-mysql/0.7.2/sqlx_mysql/types/index.html
    use sea_query::Value;
    use sqlx::{Column, Row, TypeInfo};
    crate::ProxyRow {
        values: row
            .columns()
            .iter()
            .map(|c| {
                (
                    c.name().to_string(),
                    match c.type_info().name() {
                        "TINYINT(1)" | "BOOLEAN" => {
                            Value::Bool(row.try_get(c.ordinal()).expect("Failed to get boolean"))
                        }
                        "TINYINT UNSIGNED" => Value::TinyUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned tiny integer"),
                        ),
                        "SMALLINT UNSIGNED" => Value::SmallUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned small integer"),
                        ),
                        "INT UNSIGNED" => Value::Unsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned integer"),
                        ),
                        "MEDIUMINT UNSIGNED" | "BIGINT UNSIGNED" => Value::BigUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned big integer"),
                        ),
                        "TINYINT" => Value::TinyInt(

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Make the column non-nullable in the query (COALESCE) or in the schema if a bool is expected.
  2. Handle NULL by decoding as Option in the proxy conversion (decode `Option<bool>` and map to Value::Bool(None)).
  3. Check `row.try_get` errors instead of `.expect` to surface a DbErr with the column name.
  4. Verify the sqlx version matches what sea-orm was compiled against; type_info names differ across versions.

Example fix

// before
"TINYINT(1)" | "BOOLEAN" => Value::Bool(
    row.try_get(c.ordinal()).expect("Failed to get boolean")
)
// after: tolerate NULL
"TINYINT(1)" | "BOOLEAN" => Value::Bool(
    row.try_get::<Option<bool>, _>(c.ordinal())
        .expect("Failed to get boolean")
)
Defensive patterns

Strategy: validation

Validate before calling

// before consuming proxy results, check the column for NULL
if row.try_get_raw(c.ordinal())?.is_null() && matches!(c.type_info().name(), "TINYINT(1)" | "BOOLEAN") {
    // handle NULL path instead of decoding a bare bool
}

Try / catch

// decode as Option to avoid the panic on NULL
let v: Option<bool> = row.try_get(c.ordinal())?;

Prevention

When it happens

Trigger: Executing a query through the proxy database backend (proxy feature) against MySQL where a TINYINT(1)/BOOLEAN column contains NULL, or sqlx's decoder rejects the wire value (e.g. unexpected column type after `CAST`/expressions in the SELECT).

Common situations: Proxy-style databases wrapping MySQL where a nullable `is_active BOOLEAN` column is NULL in a result row; SELECT expressions like `SELECT flag IS TRUE` returning unexpected types; sqlx version changes altering type_info names so a branch mismatches the actual value type.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/a8984e11bd147c3d. Report an issue: GitHub.