SeaQL/sea-orm · error
Failed to get small integer
Error message
Failed to get small integer
What it means
In `ProxyRow`, `SMALLINT` MySQL columns are read via `row.try_get::<i16>` and unwrapped with `.expect("Failed to get small integer")`. If the value cannot be decoded as i16 — most commonly because it is NULL, or the underlying value has a different type than the described metadata — the expect panics with this message.
Source
Thrown at src/driver/sqlx_mysql.rs:421
"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" => {
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")View on GitHub (pinned to e29bcd1b41)
Solutions
- Declare the field as `Option<i16>` if the column is nullable, or add a NOT NULL constraint
- Regenerate the entity from the live schema to match the real column type
- Fix mock/proxy test data to return `i16` values for SMALLINT columns
- Remove SELECT-list expressions (COALESCE/CAST) that alter the column's reported type
Example fix
// before pub rank: i16, // after pub rank: Option<i16>,
Defensive patterns
Strategy: validation
Validate before calling
// Verify SMALLINT columns before decoding SELECT COLUMN_TYPE, IS_NULLABLE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?; // expect COLUMN_TYPE = 'smallint', IS_NULLABLE = 'NO'
Type guard
fn is_i16_compatible(col_type: &str, nullable: bool, value_is_null: bool) -> bool {
col_type.eq_ignore_ascii_case("smallint") && !nullable && !value_is_null
} Prevention
- Use Option<i16> for nullable smallint fields
- Check LEFT JOINs that introduce NULLs into otherwise NOT NULL columns
- Keep proxy mock data as i16 for SMALLINT columns
- Regenerate entities after migrations
When it happens
Trigger: A SMALLINT column containing NULL in a result set decoded through the proxy driver, or metadata/actual-type mismatch (e.g. column altered to SMALLINT UNSIGNED or INT after description).
Common situations: Nullable smallint columns joined via LEFT JOIN yielding NULL; schema drift after migrations; proxy-driver mock rows returning i32/u16 for a column described as SMALLINT.
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
- Failed to get unsigned integer
- Failed to get unsigned big integer
- Failed to get integer
- Failed to get tiny integer
- Failed to get big integer
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/e53d9abe54b95798.
Report an issue: GitHub.