{"record":{"id":"177266f069e51a3e","repo":"SeaQL/sea-orm","slug":"failed-to-get-boolean-177266","errorCode":null,"errorMessage":"Failed to get boolean","messagePattern":"Failed to get boolean","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_sqlite.rs","lineNumber":424,"sourceCode":"    }\n}\n\n#[cfg(feature = \"proxy\")]\npub(crate) fn from_sqlx_sqlite_row_to_proxy_row(row: &sqlx::sqlite::SqliteRow) -> crate::ProxyRow {\n    // https://docs.rs/sqlx-sqlite/0.7.2/src/sqlx_sqlite/type_info.rs.html\n    // https://docs.rs/sqlx-sqlite/0.7.2/sqlx_sqlite/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                        \"BOOLEAN\" => {\n                            Value::Bool(row.try_get(c.ordinal()).expect(\"Failed to get boolean\"))\n                        }\n\n                        \"INTEGER\" => {\n                            Value::Int(row.try_get(c.ordinal()).expect(\"Failed to get integer\"))\n                        }\n\n                        \"BIGINT\" | \"INT8\" => Value::BigInt(\n                            row.try_get(c.ordinal()).expect(\"Failed to get big integer\"),\n                        ),\n\n                        \"REAL\" => {\n                            Value::Double(row.try_get(c.ordinal()).expect(\"Failed to get double\"))\n                        }\n\n                        \"TEXT\" => Value::String(\n                            row.try_get::<Option<String>, _>(c.ordinal())\n                                .expect(\"Failed to get string\")\n                                .map(Box::new),","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_sqlite.rs#L406-L442","documentation":"During proxy-row conversion (feature \"proxy\"), each SQLite column's declared type_info is matched and the value is decoded with sqlx Row::try_get. For a \"BOOLEAN\" column the library calls row.try_get::<bool>(ordinal) and unwraps it with expect(\"Failed to get boolean\"). This panics when the underlying SQLite value is NULL or cannot be decoded as a bool, because SQLite's dynamic typing can store values that do not match the declared affinity.","triggerScenarios":"Calling any query through the proxy driver against SQLite where a BOOLEAN-declared column contains NULL (the non-Option try_get used here cannot decode NULL) or a non-integer value, e.g. raw SQL inserting text into a boolean column.","commonSituations":"Raw SQL migrations inserting NULL into NOT-omitted boolean columns; schema declared BOOLEAN but data written by another tool as text; SELECT with computed expressions typed as NULL.","solutions":["Ensure BOOLEAN columns are NOT NULL or provide a default so NULL never reaches the row","Coalesce NULLs in the query: SELECT IFNULL(active, 0) AS active ...","Avoid the proxy feature or use a non-proxy driver so decoding returns DbErr instead of panicking","Cast the value in SQL to an integer and decode defensively"],"exampleFix":"// before\nSELECT active FROM \"user\";\n// after\nSELECT IFNULL(active, 0) AS active FROM \"user\";","handlingStrategy":"try-catch","validationCode":"// Before reading, coalesce NULLs and validate affinity in SQL:\n// SELECT IFNULL(active, 0) AS active FROM \"user\";\nfn is_valid_bool_cell(v: Option<i64>) -> bool { v.is_some() }","typeGuard":"fn as_bool(v: &sea_query::Value) -> Option<bool> {\n    match v { sea_query::Value::Bool(b) => Some(*b), sea_query::Value::TinyInt(i) => Some(*i != 0), _ => None }\n}","tryCatchPattern":"// Proxy conversion panics (expect), so isolate it:\nlet result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| from_sqlx_sqlite_row_to_proxy_row(&row)));\nmatch result { Ok(proxy_row) => /* ... */, Err(_) => /* fall back to non-proxy decode or DbErr::RecordNotFound-like error */ }","preventionTips":["Declare boolean columns NOT NULL with a default","Always coalesce NULLs in raw SQL feeding the proxy driver","Only write values through typed SeaORM APIs","Consider not enabling the proxy feature in production"],"tags":["sqlite","sqlx","proxy","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"}