{"record":{"id":"682d60a07ba95185","repo":"SeaQL/sea-orm","slug":"failed-to-get-unsigned-small-integer-682d60","errorCode":null,"errorMessage":"Failed to get unsigned small integer","messagePattern":"Failed to get unsigned small integer","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_mysql.rs","lineNumber":405,"sourceCode":"    use sqlx::{Column, Row, TypeInfo};\n    crate::ProxyRow {\n        values: row\n            .columns()\n            .iter()\n            .map(|c| {\n                (\n                    c.name().to_string(),\n                    match c.type_info().name() {\n                        \"TINYINT(1)\" | \"BOOLEAN\" => {\n                            Value::Bool(row.try_get(c.ordinal()).expect(\"Failed to get boolean\"))\n                        }\n                        \"TINYINT UNSIGNED\" => Value::TinyUnsigned(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get unsigned tiny integer\"),\n                        ),\n                        \"SMALLINT UNSIGNED\" => Value::SmallUnsigned(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get unsigned small integer\"),\n                        ),\n                        \"INT UNSIGNED\" => Value::Unsigned(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get unsigned integer\"),\n                        ),\n                        \"MEDIUMINT UNSIGNED\" | \"BIGINT UNSIGNED\" => Value::BigUnsigned(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get unsigned big integer\"),\n                        ),\n                        \"TINYINT\" => Value::TinyInt(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get tiny integer\"),\n                        ),\n                        \"SMALLINT\" => Value::SmallInt(\n                            row.try_get(c.ordinal())\n                                .expect(\"Failed to get small integer\"),\n                        ),\n                        \"INT\" => {","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_mysql.rs#L387-L423","documentation":"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.","triggerScenarios":"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.","commonSituations":"Nullable unsigned columns decoded through the proxy/mock driver; sqlx upgrades altering how MySQL unsigned smallints are represented, breaking the name-to-type assumption.","solutions":["Declare these columns NOT NULL or decode with Option<u16> and a fallback value.","Coalesce NULLs in the query: IFNULL(col, 0).","Align the type-info match strings with your sqlx version's reported names.","Map try_get errors to DbErr instead of using expect."],"exampleFix":"// before\n\"SMALLINT UNSIGNED\" => Value::SmallUnsigned(\n    row.try_get(c.ordinal()).expect(\"Failed to get unsigned small integer\")),\n// after\n\"SMALLINT UNSIGNED\" => Value::SmallUnsigned(\n    row.try_get::<Option<u16>, _>(c.ordinal())\n        .map_err(|e| DbErr::Query(RuntimeErr::Protocol(e.to_string())))?\n        .unwrap_or(0)),","handlingStrategy":"validation","validationCode":"-- Guard the schema before decoding:\nALTER TABLE orders MODIFY quantity SMALLINT UNSIGNED NOT NULL DEFAULT 0;","typeGuard":"fn decodable_u16(col: &Column) -> bool {\n    col.type_info().name() == \"SMALLINT UNSIGNED\" && !col.nullable()\n}","tryCatchPattern":"let converted = std::panic::catch_unwind(AssertUnwindSafe(|| ProxyRow::from_mysql_row(row, cols)));\nmatch converted {\n    Ok(r) => Ok(r),\n    Err(_) => Err(DbErr::Query(RuntimeErr::Protocol(\"unsigned smallint decode failed\".into()))),\n}","preventionTips":["Enforce NOT NULL on SMALLINT UNSIGNED columns","Use IFNULL(col, 0) when selecting possibly-null unsigned values","Re-verify type-info names after any sqlx upgrade","Add schema-aware integration tests for the proxy driver path"],"tags":["panic","mysql","type-decoding","sqlx"],"backgroundTag":"type-mismatch","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}