{"record":{"id":"228ffe8cd9643731","repo":"SeaQL/sea-orm","slug":"failed-to-get-boolean-array","errorCode":null,"errorMessage":"Failed to get boolean array","messagePattern":"Failed to get boolean array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":431,"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":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L413-L449","documentation":"Panic raised while decoding a Postgres boolean-array column: the driver matched type name \"BOOL[]\" and called `row.try_get::<Option<Vec<bool>>, _>(ordinal).expect(\"Failed to get boolean array\")`. The `Option<Vec<bool>>` target already tolerates a NULL array, so the failure means an individual element decode failed (array containing NULLs decodes as `Vec<Option<bool>>` only), or the runtime value is not actually a bool array despite the reported type name.","triggerScenarios":"Selecting a `boolean[]` column that contains NULL elements (e.g. `ARRAY[true, NULL]::boolean[]`) through ProxyRow; or a column whose type name string is \"BOOL[]\" but whose underlying data is not decodable as `Vec<bool>` (domain/array-of-domain, or a custom type named BOOL[]).","commonSituations":"Arrays built from nullable expressions (`ARRAY(SELECT b FROM ...)` producing NULL elements); array-of-DOMAIN types over boolean; stale schema where the column was migrated to a different element type; feeding a text representation like '{t,f}' stored in a non-array column that a view reports as BOOL[].","solutions":["Decode elements as Option: `row.try_get::<Option<Vec<Option<bool>>>, _>(c.ordinal())` and map `None` elements to `Value::TinyInt(None)`/skip, avoiding the element-level decode failure.","Eliminate NULL elements in SQL: `ARRAY_REMOVE(ARRAY_AGG(col), NULL)` or `COALESCE(col, ARRAY[]::boolean[])`.","Cast in the query to a plain `boolean[]` (`col::boolean[]`) if the column is a domain/array-of-domain.","Verify the physical element type with `SELECT pg_typeof(col)`; fix schema or query if it is not boolean.","Set NOT NULL / DEFAULT on elements where the model guarantees non-null booleans."],"exampleFix":"// before (panics when array contains NULL elements)\n\"BOOL[]\" => Value::Array(ArrayType::Bool,\n    row.try_get::<Option<Vec<bool>>, _>(c.ordinal()).expect(\"Failed to get boolean array\")...),\n// after (SQL-side guard)\n// SELECT array_remove(col, NULL) AS col FROM t;\n\"BOOL[]\" => Value::Array(ArrayType::Bool,\n    row.try_get::<Option<Vec<bool>>, _>(c.ordinal()).expect(\"Failed to get boolean array\")...),","handlingStrategy":"try-catch","validationCode":"// SELECT array_position(col, NULL) IS NOT NULL AS has_nulls FROM t;\n// or pre-check: SELECT bool_and(col IS NOT NULL) FROM unnest($1::boolean[]) AS col;","typeGuard":"fn as_bool_array(row: &ProxyRow, col: &str) -> Option<Vec<bool>> {\n    match row.value(col) {\n        Some(Value::Array(ArrayType::Bool, vals)) => Some(\n            vals.iter().filter_map(|v| match v {\n                Value::Bool(Some(b)) => Some(*b),\n                _ => None,\n            }).collect(),\n        ),\n        _ => None,\n    }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(|| proxy_row_get_bool_array(&row, \"flags\"));\nmatch result {\n    Ok(v) => v,\n    Err(_) => Vec::new(), // or re-query with array_remove(col, NULL)\n}","preventionTips":["Use array_remove(col, NULL) / COALESCE(array_agg(...), ARRAY[]) when aggregating into arrays.","Decode element-nullable arrays as Vec<Option<T>> in custom code paths.","Verify element types with pg_typeof before mapping to fixed Rust element types.","Cast DOMAIN arrays to base arrays (col::boolean[]) in SQL."],"tags":["postgres","sqlx","array-decode","type-decode","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"}