SeaQL/sea-orm · error

Failed to get unsigned small integer

Error message

Failed to get unsigned small integer

What it means

In `from_sqlx_mysql_row_to_proxy_row`, a column typed "SMALLINT UNSIGNED" is decoded with `row.try_get::<u16>` and `.expect("Failed to get unsigned small integer")`. The panic occurs when sqlx cannot decode the cell as u16 — usually because the value is NULL but a non-Option type was requested, or the reported column type does not match the actual decoded value.

Source

Thrown at sea-orm-sync/src/driver/sqlx_mysql.rs:397

    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. Make the column non-nullable or use COALESCE in the query.
  2. Decode as `Option<u16>` and map NULL to Value::SmallUnsigned(None).
  3. Propagate the try_get error instead of panicking to identify the offending column.
  4. Pin/align the sqlx version with sea-orm's dependency.

Example fix

// before
"SMALLINT UNSIGNED" => Value::SmallUnsigned(
    row.try_get(c.ordinal()).expect("Failed to get unsigned small integer"),
)
// after: tolerate NULL
"SMALLINT UNSIGNED" => Value::SmallUnsigned(
    row.try_get::<Option<u16>, _>(c.ordinal())
        .expect("Failed to get unsigned small integer"),
)
Defensive patterns

Strategy: validation

Validate before calling

// check NULL before decoding SMALLINT UNSIGNED as u16
if row.try_get_raw(c.ordinal())?.is_null() && c.type_info().name() == "SMALLINT UNSIGNED" {
    // handle NULL path
}

Try / catch

let v: Option<u16> = row.try_get(c.ordinal())?;

Prevention

When it happens

Trigger: Proxy backend query against MySQL returning a SMALLINT UNSIGNED column that is NULL, or whose value fails u16 decoding (expression/CAST changing the effective type).

Common situations: Nullable SMALLINT UNSIGNED columns in proxy result rows; SELECT with computed columns whose type_info name matches but value decodes differently; sqlx version drift in MySQL type mappings.

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/687363ee9996d203. Report an issue: GitHub.