SeaQL/sea-orm · error

Failed to get unsigned small integer

Error message

Failed to get unsigned small integer

What it means

The SMALLINT UNSIGNED arm decodes the column with row.try_get(c.ordinal()).expect("Failed to get unsigned small integer"), assuming a u16 value. If the value is NULL or sqlx's actual decoded type differs from the reported type-info name, try_get returns an error and the library panics rather than returning a DbErr.

Source

Thrown at src/driver/sqlx_mysql.rs:405

    use sqlx::{Column, Row, TypeInfo};
    crate::ProxyRow {
        values: row
            .columns()
            .iter()
            .map(|c| {
                (
                    c.name().to_string(),
                    match c.type_info().name() {
                        "TINYINT(1)" | "BOOLEAN" => {
                            Value::Bool(row.try_get(c.ordinal()).expect("Failed to get boolean"))
                        }
                        "TINYINT UNSIGNED" => Value::TinyUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned tiny integer"),
                        ),
                        "SMALLINT UNSIGNED" => Value::SmallUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned small integer"),
                        ),
                        "INT UNSIGNED" => Value::Unsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned integer"),
                        ),
                        "MEDIUMINT UNSIGNED" | "BIGINT UNSIGNED" => Value::BigUnsigned(
                            row.try_get(c.ordinal())
                                .expect("Failed to get unsigned big integer"),
                        ),
                        "TINYINT" => Value::TinyInt(
                            row.try_get(c.ordinal())
                                .expect("Failed to get tiny integer"),
                        ),
                        "SMALLINT" => Value::SmallInt(
                            row.try_get(c.ordinal())
                                .expect("Failed to get small integer"),
                        ),
                        "INT" => {

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Declare these columns NOT NULL or decode with Option<u16> and a fallback value.
  2. Coalesce NULLs in the query: IFNULL(col, 0).
  3. Align the type-info match strings with your sqlx version's reported names.
  4. Map try_get errors to DbErr instead of using expect.

Example fix

// before
"SMALLINT UNSIGNED" => Value::SmallUnsigned(
    row.try_get(c.ordinal()).expect("Failed to get unsigned small integer")),
// after
"SMALLINT UNSIGNED" => Value::SmallUnsigned(
    row.try_get::<Option<u16>, _>(c.ordinal())
        .map_err(|e| DbErr::Query(RuntimeErr::Protocol(e.to_string())))?
        .unwrap_or(0)),
Defensive patterns

Strategy: validation

Validate before calling

-- Guard the schema before decoding:
ALTER TABLE orders MODIFY quantity SMALLINT UNSIGNED NOT NULL DEFAULT 0;

Type guard

fn decodable_u16(col: &Column) -> bool {
    col.type_info().name() == "SMALLINT UNSIGNED" && !col.nullable()
}

Try / catch

let converted = std::panic::catch_unwind(AssertUnwindSafe(|| ProxyRow::from_mysql_row(row, cols)));
match converted {
    Ok(r) => Ok(r),
    Err(_) => Err(DbErr::Query(RuntimeErr::Protocol("unsigned smallint decode failed".into()))),
}

Prevention

When it happens

Trigger: Reading a nullable SMALLINT UNSIGNED column via the proxy row conversion, or when the driver's runtime type representation no longer matches the 'SMALLINT UNSIGNED' name this match arm expects.

Common situations: Nullable unsigned columns decoded through the proxy/mock driver; sqlx upgrades altering how MySQL unsigned smallints are represented, breaking the name-to-type assumption.

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/682d60a07ba95185. Report an issue: GitHub.