{"record":{"id":"22003aad15cb94c4","repo":"SeaQL/sea-orm","slug":"failed-to-get-boolean-22003a","errorCode":null,"errorMessage":"Failed to get boolean","messagePattern":"Failed to get boolean","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":438,"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":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L420-L456","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (nullable bool decoded as plain bool -> panic on NULL)\n\"SELECT is_active FROM users\"\n\n// after\n\"SELECT COALESCE(is_active, false) AS is_active FROM users\"\n// or in the entity: pub is_active: Option<bool>","handlingStrategy":"validation","validationCode":"// Detect nullable BOOL columns before mapping them to plain bool:\nlet nullable = db.query_all(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT column_name FROM information_schema.columns\n     WHERE table_name = 'users' AND column_name = 'is_active' AND is_nullable = 'YES'\",\n)).await?;\nassert!(nullable.is_empty(), \"map nullable bool to Option<bool> or COALESCE in SQL\");","typeGuard":null,"tryCatchPattern":"// If you control the query, avoid the panic by coercing NULL in SQL;\n// for entity mapping, use Option<bool>:\n#[derive(DeriveEntityModel)]\n#[sea_orm(table_name = \"users\")]\npub struct Model {\n    pub id: i32,\n    pub is_active: Option<bool>, // before: bool (panics on NULL)\n}","preventionTips":["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."],"tags":["postgres","sqlx","null-value","boolean","panic"],"backgroundTag":"null-argument","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"}