SeaQL/sea-orm · error

Failed to get bytes array

Error message

Failed to get bytes array

What it means

This panic originates from `.expect("Failed to get bytes array")` in ProxyRow (src/driver/sqlx_postgres.rs:582). For BYTEA[] columns (behind `postgres-array`), the code decodes `Option<Vec<Vec<u8>>>`; failure to decode into that type panics. Usually the value isn't a bytea array, its element type differs, or array support wasn't enabled in sqlx.

Solutions

  1. Enable `postgres-array` on both sea-orm and sqlx and rebuild.
  2. Verify the type with `SELECT array_typeof(col)` and cast in SQL: `col::bytea[]`.
  3. Upgrade or pin sea-orm/sqlx to compatible versions with bytea-array decoding support.
  4. Capture the underlying sqlx error with RUST_LOG=sqlx=debug before the panic point.
  5. Convert the expect into a DbErr::Custom error including the column ordinal.

Example fix

// before
row.try_get::<Option<Vec<Vec<u8>>>, _>(c.ordinal()).expect("Failed to get bytes array")
// after
row.try_get::<Option<Vec<Vec<u8>>>, _>(c.ordinal())
    .map_err(|e| DbErr::Custom(format!("bytea[] decode failed col {}: {e}", c.ordinal())))?
Defensive patterns

Strategy: validation

Validate before calling

// Verify bytea[] elements:
// SELECT array_typeof(col) FROM t LIMIT 1;  -- expect 'bytea'
// Or cast: SELECT col::bytea[] FROM ...

Type guard

fn is_bytea_array_col(c: &ProxyColumn) -> bool {
    c.ty == "BYTEA[]"
}

Try / catch

std::panic::catch_unwind(|| read_row(row))
    .map_err(|p| DbErr::Custom(format!("bytea[] decode panic: {p:?}")))?;

Prevention

When it happens

Trigger: Reading bytea[] produced by array_agg over bytea in an sqlx version lacking array-of-bytea decode support, a column actually holding scalar bytea or text[], or type-name metadata reporting BYTEA[] for a mismatched underlying type.

Common situations: Missing `postgres-array` feature, sqlx/sea-orm version skew after upgrade, schema drift, or extension-generated arrays with nonstandard element OIDs.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/64c09975e8f24063. Report an issue: GitHub.

Appendix: source

Thrown at src/driver/sqlx_postgres.rs:582

                                .expect("Failed to get string array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::String(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        "BYTEA" => Value::Bytes(
                            row.try_get::<Option<Vec<u8>>, _>(c.ordinal())
                                .expect("Failed to get bytes"),
                        ),
                        #[cfg(feature = "postgres-array")]
                        "BYTEA[]" => Value::Array(
                            sea_query::ArrayType::Bytes,
                            row.try_get::<Option<Vec<Vec<u8>>>, _>(c.ordinal())
                                .expect("Failed to get bytes array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::Bytes(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        #[cfg(feature = "with-bigdecimal")]
                        "NUMERIC" => Value::BigDecimal(
                            row.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())
                                .expect("Failed to get numeric"),
                        ),
                        #[cfg(all(
                            feature = "with-rust_decimal",
                            not(feature = "with-bigdecimal")
                        ))]

View on GitHub (pinned to e29bcd1b41)