SeaQL/sea-orm · error

Failed to get bytes

Error message

Failed to get bytes

What it means

`ProxyRow` decodes MySQL binary columns (BIT, BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB) with `row.try_get::<Option<Vec<u8>>>` and `.expect("Failed to get bytes")`. Because the target is `Option<Vec<u8>>`, NULL is handled — so this panic means sqlx fundamentally could not decode the cell as binary data (incompatible type, driver/charset conversion issue, or metadata/actual-type mismatch).

Source

Thrown at src/driver/sqlx_mysql.rs:439

                                .expect("Failed to get small integer"),
                        ),
                        "INT" => {
                            Value::Int(row.try_get(c.ordinal()).expect("Failed to get integer"))
                        }
                        "MEDIUMINT" | "BIGINT" => Value::BigInt(
                            row.try_get(c.ordinal()).expect("Failed to get big integer"),
                        ),
                        "FLOAT" => {
                            Value::Float(row.try_get(c.ordinal()).expect("Failed to get float"))
                        }
                        "DOUBLE" => {
                            Value::Double(row.try_get(c.ordinal()).expect("Failed to get double"))
                        }

                        "BIT" | "BINARY" | "VARBINARY" | "TINYBLOB" | "BLOB" | "MEDIUMBLOB"
                        | "LONGBLOB" => Value::Bytes(
                            row.try_get::<Option<Vec<u8>>, _>(c.ordinal())
                                .expect("Failed to get bytes")
                                .map(Box::new),
                        ),

                        "CHAR" | "VARCHAR" | "TINYTEXT" | "TEXT" | "MEDIUMTEXT" | "LONGTEXT" => {
                            Value::String(
                                row.try_get::<Option<String>, _>(c.ordinal())
                                    .expect("Failed to get string")
                                    .map(Box::new),
                            )
                        }

                        #[cfg(feature = "with-chrono")]
                        "TIMESTAMP" => Value::ChronoDateTimeUtc(
                            row.try_get::<Option<chrono::DateTime<chrono::Utc>>, _>(c.ordinal())
                                .expect("Failed to get timestamp")
                                .map(Box::new),
                        ),
                        #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Fix the proxy/mock handler to return `Vec<u8>` values for binary columns
  2. If the column is actually text, align the entity/SQL so it is decoded by the string arm instead
  3. Check BIT column widths and select them via the entity's typed mapping
  4. Regenerate entities from the live schema to remove type drift

Example fix

// before (mock proxy row for a BLOB column)
Value::String("binary-data".into())
// after
Value::Bytes(Box::new(vec![0x62, 0x69, 0x6e]))
Defensive patterns

Strategy: validation

Validate before calling

// Verify binary columns and that handlers supply bytes
SELECT COLUMN_TYPE, IS_NULLABLE FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?;
// COLUMN_TYPE should be one of: bit/binary/varbinary/tinyblob/blob/mediumblob/longblob

Type guard

fn is_binary_column(col_type: &str) -> bool {
    matches!(col_type.to_ascii_lowercase().as_str(),
        "bit" | "binary" | "varbinary" | "tinyblob" | "blob" | "mediumblob" | "longblob")
}

Prevention

When it happens

Trigger: A binary-typed column whose driver-side value is not decodable as bytes — e.g. mock proxy rows supplying a string/JSON value for a BLOB column, or a BIT column value surfaced in a form sqlx won't decode into Vec<u8> — while using the proxy driver.

Common situations: Proxy/mock test handlers emitting text values for BLOB columns; BIT(1) columns interacting poorly with driver typing; schema drift where a text column was described as binary; encoding/charset conversions corrupting the value type.

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/4fa8aed47ce0099d. Report an issue: GitHub.