{"record":{"id":"b82fc5d2f70f7153","repo":"SeaQL/sea-orm","slug":"failed-to-get-boolean-array-b82fc5","errorCode":null,"errorMessage":"Failed to get boolean array","messagePattern":"Failed to get boolean array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":444,"sourceCode":"    // 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\"),\n                        ),\n                        #[cfg(feature = \"postgres-array\")]\n                        \"\\\"CHAR\\\"[]\" => Value::Array(\n                            sea_query::ArrayType::TinyInt,\n                            row.try_get::<Option<Vec<i8>>, _>(c.ordinal())\n                                .expect(\"Failed to get small integer array\")","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L426-L462","documentation":"This panic comes from `.expect(\"Failed to get boolean array\")` in sea-orm's sqlx Postgres ProxyRow conversion for \"BOOL[]\" columns (behind the `postgres-array` feature), decoding into `Option<Vec<bool>>`. The outer Option handles SQL NULL, but a decode failure -- such as a multidimensional array, an array containing NULL elements where Vec<bool> cannot hold them, or a type mismatch -- makes try_get error and the expect panic.","triggerScenarios":"Reading a Postgres BOOLEAN[] column where `row.try_get::<Option<Vec<bool>>, _>(c.ordinal())` fails: the column is a multidimensional array (bool[][]), contains NULL elements (NULL inside the array is not representable in Vec<bool>), or the runtime type differs from BOOL[].","commonSituations":"Arrays with NULL elements (`ARRAY[true,NULL]::bool[]`); dimensionality drift after schema changes; selecting bool[] via raw SQL proxy queries; enabling/disabling the postgres-array feature so decode expectations change; sqlx version upgrades altering array decoding.","solutions":["Ensure array elements are never NULL: `UPDATE t SET col = ARRAY_REMOVE(col, NULL)` or add NOT NULL constraints on elements at write time.","Cast multidimensional arrays to 1-D in SQL or select with `unnest(col)` instead of the array directly.","If NULL elements are legitimate, select as text (`col::text`) and parse manually into Vec<Option<bool>>.","Verify the `postgres-array` feature is enabled consistently and entity types use Vec<bool> matching a true 1-D bool[] column.","Align sqlx/sea-orm versions if array decoding behavior changed after an upgrade."],"exampleFix":"// before (array with NULL elements panics)\n\"SELECT flags FROM items\"  -- flags = '{t,null}'::bool[]\n\n// after (strip NULLs at query time)\n\"SELECT ARRAY_REMOVE(flags, NULL) AS flags FROM items\"","handlingStrategy":"validation","validationCode":"// Ensure the array is 1-D and contains no NULL elements before decoding as Vec<bool>:\nlet bad = db.query_all(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT id FROM items\n      WHERE flags IS NOT NULL\n        AND (array_ndims(flags) <> 1 OR EXISTS (SELECT 1 FROM unnest(flags) v WHERE v IS NULL))\",\n)).await?;\nassert!(bad.is_empty(), \"flags must be a 1-D bool[] without NULL elements\");","typeGuard":null,"tryCatchPattern":"// Sanitize in SQL to keep the decode total:\n// SELECT ARRAY_REMOVE(flags, NULL) AS flags FROM items\n// Or parse from text for full control:\nlet raw: Option<String> = row.try_get(\"flags\")?;\nlet flags: Vec<Option<bool>> = raw\n    .map(|s| s.trim_matches(|c| c == '{' || c == '}')\n        .split(',')\n        .map(|x| match x.trim() { \"t\" | \"true\" => Some(true), \"f\" | \"false\" => Some(false), _ => None })\n        .collect())\n    .unwrap_or_default();","preventionTips":["Never store NULL elements inside boolean arrays; use ARRAY_REMOVE or enforce at write time.","Keep array columns strictly 1-D (bool[] not bool[][]).","Ensure the postgres-array feature is enabled consistently on sea-orm and sqlx.","Add data-quality checks for array columns in migrations or CI."],"tags":["postgres","sqlx","array","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"}