{"record":{"id":"a3e935f358b96130","repo":"SeaQL/sea-orm","slug":"failed-to-get-bytes-a3e935","errorCode":null,"errorMessage":"Failed to get bytes","messagePattern":"Failed to get bytes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":576,"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":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L558-L594","documentation":"This panic is raised by `.expect(\"Failed to get bytes\")` in ProxyRow's PostgreSQL backend (src/driver/sqlx_postgres.rs:576). For BYTEA columns the driver decodes `Option<Vec<u8>>`; it panics when sqlx cannot decode the value as bytea. Typically the value is actually text or another binary variant, or the metadata type name says BYTEA for a non-bytea column.","triggerScenarios":"Reading a bytea column whose rows were written as text (or vice versa) via a different client, selecting a large-object reference or a view column typed differently from bytea, or a stale cached column list where ordinal/type no longer matches the actual result row.","commonSituations":"Schema drift after ALTER COLUMN TYPE, using a proxy/sharding layer with a cached schema, sqlx version mismatch changing bytea decode behavior, or comparing a `text` hex-encoded blob mislabeled as bytea.","solutions":["Confirm the column type is genuinely bytea (`SELECT format_type(atttypid, ...)`) and cast in SQL (`col::bytea`) when needed.","Refresh the query/column metadata after any schema migration so ordinals and types match.","Align sea-orm and sqlx versions and rebuild; bytea handling changed across sqlx versions.","Enable RUST_LOG=sqlx=debug to see the real decode error before the expect panics.","Replace expect with an error mapped to DbErr::Custom naming the column."],"exampleFix":"// before\n\"BYTEA\" => Value::Bytes(\n    row.try_get::<Option<Vec<u8>>, _>(c.ordinal()).expect(\"Failed to get bytes\"),\n)\n// after\n\"BYTEA\" => Value::Bytes(\n    row.try_get::<Option<Vec<u8>>, _>(c.ordinal())\n        .map_err(|e| DbErr::Custom(format!(\"bytea decode failed col {}: {e}\", c.ordinal())))?,\n)","handlingStrategy":"validation","validationCode":"// Confirm the column is bytea:\n// SELECT data_type FROM information_schema.columns\n//   WHERE table_name=$1 AND column_name=$2;  -- expect 'bytea'\n// Or cast: SELECT col::bytea FROM ...","typeGuard":"fn is_bytea_col(c: &ProxyColumn) -> bool {\n    c.ty == \"BYTEA\"\n}","tryCatchPattern":"std::panic::catch_unwind(|| read_row(row))\n    .map_err(|p| DbErr::Custom(format!(\"bytea decode panic: {p:?}\")))?;","preventionTips":["Cast to ::bytea in SQL for binary-tolerant reads.","Do not write text into bytea columns via other clients without casts.","Refresh cached column metadata after schema changes.","Keep sea-orm/sqlx versions matched.","Test binary round-trips (write then read) in integration tests."],"tags":["postgres","sqlx","bytes","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-17T15:17:12.973Z"}