SeaQL/sea-orm · error

Failed to get integer

Error message

Failed to get integer

What it means

`ProxyRow` decodes MySQL `INT` columns with `row.try_get::<i32>` followed by `.expect("Failed to get integer")`. A sqlx decode error (NULL value, or value whose type does not match the described INT metadata) causes this panic. It signals that the row's actual value does not conform to the declared non-nullable signed 32-bit integer column.

Source

Thrown at src/driver/sqlx_mysql.rs:424

                        ),
                        "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")
                                .map(Box::new),
                        ),

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Make the column NOT NULL or change the entity field to `Option<i32>`
  2. Check the SQL for joins/aggregations that produce NULL in an otherwise NOT NULL column
  3. Regenerate entities to align with the current schema
  4. Fix proxy/mock rows to return `i32` values for INT columns

Example fix

// before (LEFT JOIN can yield NULL)
pub parent_id: i32,
// after
pub parent_id: Option<i32>,
Defensive patterns

Strategy: validation

Validate before calling

// Verify INT columns before decoding
SELECT COLUMN_TYPE, IS_NULLABLE FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?;
// expect COLUMN_TYPE = 'int', IS_NULLABLE = 'NO'

Type guard

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

Prevention

When it happens

Trigger: An INT column that is NULL in the decoded row, or whose underlying value is not i32-compatible (schema drift, mock proxy value of wrong type), while fetching through the proxy driver path.

Common situations: Primary-key/foreign-key INT columns coming back NULL from outer joins or aggregate queries (COUNT over empty group with wrong SELECT); entities not regenerated after a migration changed nullability; proxy test handlers returning u32 for an INT column.

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