{"record":{"id":"b8a3ad07467b9995","repo":"SeaQL/sea-orm","slug":"failed-to-get-bytes-b8a3ad","errorCode":null,"errorMessage":"Failed to get bytes","messagePattern":"Failed to get bytes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":563,"sourceCode":"                                .expect(\"Failed to get string\"),\n                        ),\n                        #[cfg(feature = \"postgres-array\")]\n                        \"VARCHAR[]\" | \"CHAR[]\" | \"TEXT[]\" | \"NAME[]\" => Value::Array(\n                            sea_query::ArrayType::String,\n                            row.try_get::<Option<Vec<String>>, _>(c.ordinal())\n                                .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())","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L545-L581","documentation":"This panic comes from `.expect(\"Failed to get bytes\")` in `ProxyRow`, where a Postgres BYTEA column is decoded via `row.try_get::<Option<Vec<u8>>>`. It fires when sqlx cannot decode the value as binary -- typically the runtime column type OID is not `bytea` (e.g. the column is actually TEXT/VARCHAR holding encoded data, or was altered to another type). Since the code uses `expect`, the driver's decode error becomes a panic that kills the query.","triggerScenarios":"Any SeaORM query returning a column matched as BYTEA that cannot be decoded as Option<Vec<u8>>: the column's real type is text/varchar (common when data was migrated from another DB), or the column was ALTERed away from bytea while the model still maps it to bytes.","commonSituations":"Migrating from MySQL blob columns into TEXT while the entity still expects Vec<u8>. `ALTER COLUMN ... TYPE TEXT` to store hex/base64 strings. Reading through views that cast bytea to text. sqlx/sea-orm version skew changing type mapping.","solutions":["Confirm the actual column type (`\\d table`); if it is TEXT storing base64/hex, either change the entity field to String and decode in application code, or ALTER the column back to BYTEA.","Cast in the query when the column is genuinely binary under another name: `SELECT decode(col, 'base64')::BYTEA AS col`.","Update the entity mapping so the Rust type matches the column (String for text, Vec<u8> for bytea).","Align sea-orm and sqlx versions if a dependency upgrade introduced the failure."],"exampleFix":"// before: entity expects bytea but the column is TEXT holding base64\npub blob: Vec<u8>,\n\n// after: read as String and decode where needed\npub blob: String, // then base64::decode(&blob) in application code","handlingStrategy":"validation","validationCode":"let row: (String,) = sqlx::query_as(\n    \"SELECT data_type FROM information_schema.columns WHERE table_name = $1 AND column_name = $2\"\n).bind(\"my_table\").bind(\"blob\").fetch_one(&db).await?;\nassert_eq!(row.0, \"bytea\", \"blob must be BYTEA, got {}\", row.0);","typeGuard":"fn as_bytes(v: &sea_orm::Value) -> Option<Vec<u8>> {\n    match v {\n        sea_orm::Value::Bytes(b) => b.clone(),\n        _ => None,\n    }\n}","tryCatchPattern":null,"preventionTips":["Map Vec<u8> entity fields only to genuine BYTEA columns; use String for base64/hex-encoded text storage.","Check column types when migrating data from other databases (MySQL blob -> Postgres).","Keep migrations in SeaORM so entity/column mappings cannot silently drift.","Use decode(col,'base64')::BYTEA casts when binary data lives in text columns."],"tags":["postgres","sqlx","bytea","type-mismatch","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"}