{"record":{"id":"d61501c1201dbc45","repo":"SeaQL/sea-orm","slug":"failed-to-get-bytes-array","errorCode":null,"errorMessage":"Failed to get bytes array","messagePattern":"Failed to get bytes array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":569,"sourceCode":"                                .expect(\"Failed to get string array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::String(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        \"BYTEA\" => Value::Bytes(\n                            row.try_get::<Option<Vec<u8>>, _>(c.ordinal())\n                                .expect(\"Failed to get bytes\"),\n                        ),\n                        #[cfg(feature = \"postgres-array\")]\n                        \"BYTEA[]\" => Value::Array(\n                            sea_query::ArrayType::Bytes,\n                            row.try_get::<Option<Vec<Vec<u8>>>, _>(c.ordinal())\n                                .expect(\"Failed to get bytes array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::Bytes(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-bigdecimal\")]\n                        \"NUMERIC\" => Value::BigDecimal(\n                            row.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())\n                                .expect(\"Failed to get numeric\"),\n                        ),\n                        #[cfg(all(\n                            feature = \"with-rust_decimal\",\n                            not(feature = \"with-bigdecimal\")\n                        ))]","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L551-L587","documentation":"This panic comes from `.expect(\"Failed to get bytes array\")` in `ProxyRow`, decoding a Postgres BYTEA[] column as `Option<Vec<Vec<u8>>>` (behind `postgres-array`). It fires when sqlx cannot decode the array into `Vec<Vec<u8>>` because the array element type OID is not `bytea` (e.g. the column is text[] or was ALTERed), or the value's structure is not a valid bytea array. The `expect` escalates the decode failure into a panic.","triggerScenarios":"Querying a BYTEA[] column whose real element type is not bytea -- after `ALTER COLUMN ... TYPE TEXT[]`, or when data was imported as string arrays, or a view/cast changes the array type before the driver sees it.","commonSituations":"Schema drift between entity `Vec<Vec<u8>>` and DB column of another array type. Migrations converting bytea[] to jsonb or text[] for tooling compatibility. FDWs or views remapping array types. sea-orm/sqlx version skew.","solutions":["Verify the actual column type (`\\d table`); make the entity field match (Vec<Vec<u8>> only for bytea[]).","Cast in the query: `SELECT col::BYTEA[] AS col` to force the element type.","If the data was moved to text[]/jsonb, change the model to String/Json and encode/decode in application code.","Keep sea-orm/sqlx versions aligned with `postgres-array` enabled."],"exampleFix":"// before: entity expects bytea[] but the column was altered to text[]\npub files: Vec<Vec<u8>>,\n\n// after: match the actual type\npub files: Vec<String>,","handlingStrategy":"validation","validationCode":"let elem: (String,) = sqlx::query_as(\n    \"SELECT format_type(a.atttypid, a.atttypmod) FROM pg_attribute a WHERE a.attrelid = $1::regclass AND a.attname = $2\"\n).bind(\"my_table\").bind(\"files\").fetch_one(&db).await?;\nassert_eq!(elem.0, \"bytea[]\", \"expected bytea[]\");","typeGuard":"fn as_bytes_array(v: &sea_orm::Value) -> Option<Vec<Vec<u8>>> {\n    match v {\n        sea_orm::Value::Array(sea_orm::ArrayType::Bytes, items) => Some(\n            items.iter().filter_map(|x| match x {\n                sea_orm::Value::Bytes(b) => b.clone(),\n                _ => None,\n            }).collect(),\n        ),\n        _ => None,\n    }\n}","tryCatchPattern":null,"preventionTips":["Pair Vec<Vec<u8>> fields only with bytea[] columns.","Avoid ALTERs converting bytea[] to text[]/jsonb without updating entities.","Enable the `postgres-array` feature for array-typed entities.","Cast (::BYTEA[]) in raw SQL against columns with uncertain element types."],"tags":["postgres","sqlx","bytea","array","type-mismatch"],"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"}