{"record":{"id":"8137aaa33c1be2ec","repo":"SeaQL/sea-orm","slug":"failed-to-get-boolean-8137aa","errorCode":null,"errorMessage":"Failed to get boolean","messagePattern":"Failed to get boolean","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":425,"sourceCode":"    }\n}\n\n#[cfg(feature = \"proxy\")]\npub(crate) fn from_sqlx_postgres_row_to_proxy_row(row: &sqlx::postgres::PgRow) -> crate::ProxyRow {\n    // https://docs.rs/sqlx-postgres/0.7.2/src/sqlx_postgres/type_info.rs.html\n    // https://docs.rs/sqlx-postgres/0.7.2/sqlx_postgres/types/index.html\n    use sea_query::Value;\n    use sqlx::{Column, Row, TypeInfo};\n    crate::ProxyRow {\n        values: row\n            .columns()\n            .iter()\n            .map(|c| {\n                (\n                    c.name().to_string(),\n                    match c.type_info().name() {\n                        \"BOOL\" => {\n                            Value::Bool(row.try_get(c.ordinal()).expect(\"Failed to get boolean\"))\n                        }\n                        #[cfg(feature = \"postgres-array\")]\n                        \"BOOL[]\" => Value::Array(\n                            sea_query::ArrayType::Bool,\n                            row.try_get::<Option<Vec<bool>>, _>(c.ordinal())\n                                .expect(\"Failed to get boolean array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::Bool(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        \"\\\"CHAR\\\"\" => Value::TinyInt(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get small integer\"),","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L407-L443","documentation":"This is not a returned error but a panic: while converting a sqlx Postgres row into a sea-orm `ProxyRow`, the driver matched a column whose type name is \"BOOL\" and called `row.try_get::<bool>(ordinal).expect(\"Failed to get boolean\")`. `try_get` fails when the runtime value cannot be decoded as `bool` (most commonly because the value is NULL, or the underlying column type differs from the reported type name). The library uses `.expect` because it trusts the type-info match, so any mismatch aborts the thread.","triggerScenarios":"Fetching a row via the sync Postgres driver where a column reports `type_info().name() == \"BOOL\"` but `row.try_get::<bool, _>(ordinal)` returns Err — i.e. the value is NULL (sqlx `UnexpectedNullError`) or the physical column is a compatible-but-different type (e.g. a domain over bool, or a custom type shadowing BOOL in a schema earlier in `search_path`).","commonSituations":"Querying a nullable boolean column directly through ProxyRow instead of through an entity model that wraps it in `Option<bool>`; using a Postgres DOMAIN type over boolean that reports as the domain name; a schema/search_path change making `BOOL` resolve to a user-defined type; reading a `bool` column whose value is NULL because of a LEFT JOIN miss.","solutions":["Read the column as `Option<bool>` (change to `row.try_get::<Option<bool>, _>(c.ordinal())` and map to `Value::Bool(opt)` or `Value::TinyInt(None)`) so NULL no longer panics.","Make the column NOT NULL (or add a DEFAULT) with `ALTER TABLE t ALTER COLUMN col SET NOT NULL;` so a scalar `bool` decode is always valid.","COALESCE the column in the query (`COALESCE(col, false)`) if NULL should be treated as false.","Check `search_path`/schema for a user-defined type named BOOL shadowing the builtin; qualify or rename it.","If the mismatch comes from a DOMAIN type, decode via the base type or cast in SQL (`col::boolean`)."],"exampleFix":"// before (panics on NULL)\n\"BOOL\" => Value::Bool(row.try_get(c.ordinal()).expect(\"Failed to get boolean\")),\n// after (NULL-safe)\n\"BOOL\" => Value::Bool(\n    row.try_get::<Option<bool>, _>(c.ordinal())\n        .expect(\"Failed to get boolean\")\n        .unwrap_or_default(),\n),","handlingStrategy":"try-catch","validationCode":"// inspect column types/typmods before running the query\nlet types: Vec<String> = cols.iter().map(|c| format!(\"{}:{}\", c.name(), c.type_info().name())).collect();\n// and check nullability in the catalog:\n// SELECT column_name, is_nullable FROM information_schema.columns\n//   WHERE table_name = 't' AND data_type IN ('boolean');","typeGuard":"fn as_bool(row: &ProxyRow, col: &str) -> Option<bool> {\n    match row.value(col) {\n        Some(Value::Bool(v)) => v,\n        _ => None,\n    }\n}","tryCatchPattern":"// the library panics (expect), so guard at the query boundary\nlet result = std::panic::catch_unwind(|| proxy_row_get_bool(&row, \"is_active\"));\nmatch result {\n    Ok(v) => v,\n    Err(_) => treat_as_null_or_default(), // fall back / log column metadata\n}","preventionTips":["Prefer Option<bool> mappings for nullable boolean columns instead of scalar decodes.","Add NOT NULL + DEFAULT to boolean columns your model treats as required.","Use COALESCE in queries over LEFT JOINs to avoid NULLs in scalar columns.","Check pg_typeof/search_path for DOMAINs or user types shadowing builtin names."],"tags":["postgres","sqlx","type-decode","null-value","panic"],"backgroundTag":"type-mismatch","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}