{"record":{"id":"687363ee9996d203","repo":"SeaQL/sea-orm","slug":"failed-to-get-unsigned-small-integer","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":"sea-orm-sync/src/driver/sqlx_mysql.rs","lineNumber":397,"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":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_mysql.rs#L379-L415","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Make the column non-nullable or use COALESCE in the query.","Decode as `Option<u16>` and map NULL to Value::SmallUnsigned(None).","Propagate the try_get error instead of panicking to identify the offending column.","Pin/align the sqlx version with sea-orm's dependency."],"exampleFix":"// before\n\"SMALLINT UNSIGNED\" => Value::SmallUnsigned(\n    row.try_get(c.ordinal()).expect(\"Failed to get unsigned small integer\"),\n)\n// after: tolerate NULL\n\"SMALLINT UNSIGNED\" => Value::SmallUnsigned(\n    row.try_get::<Option<u16>, _>(c.ordinal())\n        .expect(\"Failed to get unsigned small integer\"),\n)","handlingStrategy":"validation","validationCode":"// check NULL before decoding SMALLINT UNSIGNED as u16\nif row.try_get_raw(c.ordinal())?.is_null() && c.type_info().name() == \"SMALLINT UNSIGNED\" {\n    // handle NULL path\n}","typeGuard":null,"tryCatchPattern":"let v: Option<u16> = row.try_get(c.ordinal())?;","preventionTips":["Make SMALLINT UNSIGNED columns NOT NULL or coalesce defaults in SQL.","Include NULL rows in proxy integration tests.","Don't alias columns in ways that obscure the real type.","Verify sqlx type mappings after any dependency upgrade."],"tags":["mysql","sqlx","proxy","type-mismatch","null-value","panic"],"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"}