SeaQL/sea-orm · error

Failed to get tiny integer

Error message

Failed to get tiny integer

What it means

`ProxyRow` decodes MySQL `TINYINT` columns by calling `row.try_get::<i8>` and unwrapping with `.expect("Failed to get tiny integer")`. A decode failure (NULL value, or the value cannot be converted to i8) panics with this message. Note MySQL TINYINT(1) is often used as BOOLEAN, so a bool-typed value in a TINYINT column can also trip this path depending on driver typing.

Source

Thrown at src/driver/sqlx_mysql.rs:417

                        "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" => {
                            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"))
                        }

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Change the entity field to `Option<i8>` (or `Option<bool>` for TINYINT(1)) so NULL/mismatch is represented safely
  2. For boolean columns, select them through the entity (which maps bool) rather than raw SQL with TINYINT metadata
  3. Fix proxy/mock handlers to emit `i8` values for columns described as TINYINT
  4. Regenerate entities after schema changes to remove type drift

Example fix

// before
pub flag: i8,
// after (for a NULLable TINYINT)
pub flag: Option<i8>,
Defensive patterns

Strategy: validation

Validate before calling

// TINYINT: confirm nullability and that bool-mapped TINYINT(1) is selected via the entity
SELECT COLUMN_TYPE, IS_NULLABLE FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?;

Type guard

fn is_i8_compatible(col_type: &str, nullable: bool, value_is_null: bool) -> bool {
    col_type.eq_ignore_ascii_case("tinyint") && !nullable && !value_is_null
}

Prevention

When it happens

Trigger: A TINYINT column that is NULL in the result set, or declared/mocked with a type sqlx will not decode as `i8` (e.g. bool from a TINYINT(1) alias, or string in a mock proxy row), while decoding through the proxy driver.

Common situations: Boolean-mapped TINYINT(1) columns decoded through raw SQL bypassing SeaORM's bool mapping; NULL tinyint in LEFT JOIN results; proxy test handlers returning `true/false` for a column described as `TINYINT`.

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/5cb9d988ba891dd5. Report an issue: GitHub.