SeaQL/sea-orm · error
Failed to get boolean
Error message
Failed to get boolean
What it means
This panic is raised by `.expect("Failed to get boolean")` in sea-orm's sqlx Postgres ProxyRow conversion when a column whose type_info().name() is "BOOL" is decoded with `row.try_get::<bool, _>(c.ordinal())`. Unlike nullable variants, this branch decodes a non-Option bool, so a NULL in a BOOL column makes sqlx return an UnexpectedNullError and the expect panics. It can also fire on a runtime type mismatch between the reported type and the actual value.
Source
Thrown at src/driver/sqlx_postgres.rs:438
}
}
#[cfg(feature = "proxy")]
pub(crate) fn from_sqlx_postgres_row_to_proxy_row(row: &sqlx::postgres::PgRow) -> crate::ProxyRow {
// https://docs.rs/sqlx-postgres/0.7.2/src/sqlx_postgres/type_info.rs.html
// https://docs.rs/sqlx-postgres/0.7.2/sqlx_postgres/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() {
"BOOL" => {
Value::Bool(row.try_get(c.ordinal()).expect("Failed to get boolean"))
}
#[cfg(feature = "postgres-array")]
"BOOL[]" => Value::Array(
sea_query::ArrayType::Bool,
row.try_get::<Option<Vec<bool>>, _>(c.ordinal())
.expect("Failed to get boolean array")
.map(|vals| {
Box::new(
vals.into_iter()
.map(|val| Value::Bool(Some(val)))
.collect(),
)
}),
),
"\"CHAR\"" => Value::TinyInt(
row.try_get(c.ordinal())
.expect("Failed to get small integer"),View on GitHub (pinned to e29bcd1b41)
Solutions
- Add `NOT NULL DEFAULT false` to the boolean column, or COALESCE in SQL: `COALESCE(is_active, false) AS is_active`.
- Ensure your entity/model column is declared as Option<bool> if the DB column is nullable.
- Avoid selecting NULLable booleans through raw proxy queries without handling NULL.
- Check for expressions returning BOOL that can yield NULL (e.g. comparisons with NULL); wrap in COALESCE.
- Regenerate entities with sea-orm-cli so Rust types match the schema nullability.
Example fix
// before (nullable bool decoded as plain bool -> panic on NULL) "SELECT is_active FROM users" // after "SELECT COALESCE(is_active, false) AS is_active FROM users" // or in the entity: pub is_active: Option<bool>
Defensive patterns
Strategy: validation
Validate before calling
// Detect nullable BOOL columns before mapping them to plain bool:
let nullable = db.query_all(Statement::from_string(
DatabaseBackend::Postgres,
"SELECT column_name FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'is_active' AND is_nullable = 'YES'",
)).await?;
assert!(nullable.is_empty(), "map nullable bool to Option<bool> or COALESCE in SQL"); Try / catch
// If you control the query, avoid the panic by coercing NULL in SQL;
// for entity mapping, use Option<bool>:
#[derive(DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
pub id: i32,
pub is_active: Option<bool>, // before: bool (panics on NULL)
} Prevention
- Declare Option<bool> in models for any nullable boolean column.
- Add NOT NULL DEFAULT to boolean columns where a NULL state is meaningless.
- Use COALESCE(col, false) in raw SQL selecting booleans.
- Regenerate entities after schema nullability changes.
When it happens
Trigger: Selecting a Postgres BOOLEAN column that is NULL (the non-Option `try_get::<bool>` fails with UnexpectedNullError), or a column reported as BOOL whose value cannot decode as bool -- typically in raw/proxy query paths.
Common situations: Raw SQL selecting nullable boolean columns into models that expect bool; proxy/driver-level row conversions in tests or custom drivers; schema changes that made a previously NOT NULL boolean nullable; joins producing NULL booleans.
Related errors
- Failed to get boolean
- Failed to get small integer
- Failed to get integer
- Failed to get big integer
- Failed to get boolean array
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/22003aad15cb94c4.
Report an issue: GitHub.