{"record":{"id":"9c28e3023757cdf3","repo":"SeaQL/sea-orm","slug":"failed-to-get-decimal","errorCode":null,"errorMessage":"Failed to get decimal","messagePattern":"Failed to get decimal","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_mysql.rs","lineNumber":517,"sourceCode":"                                .map(Box::new),\n                        ),\n                        #[cfg(all(feature = \"with-time\", not(feature = \"with-chrono\")))]\n                        \"YEAR\" => Value::TimeDate(\n                            row.try_get::<Option<time::Date>, _>(c.ordinal())\n                                .expect(\"Failed to get year\")\n                                .map(Box::new),\n                        ),\n\n                        \"ENUM\" | \"SET\" | \"GEOMETRY\" => Value::String(\n                            row.try_get::<Option<String>, _>(c.ordinal())\n                                .expect(\"Failed to get serialized string\")\n                                .map(Box::new),\n                        ),\n\n                        #[cfg(feature = \"with-bigdecimal\")]\n                        \"DECIMAL\" => Value::BigDecimal(\n                            row.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())\n                                .expect(\"Failed to get decimal\")\n                                .map(Box::new),\n                        ),\n                        #[cfg(all(\n                            feature = \"with-rust_decimal\",\n                            not(feature = \"with-bigdecimal\")\n                        ))]\n                        \"DECIMAL\" => Value::Decimal(\n                            row.try_get::<Option<rust_decimal::Decimal>, _>(c.ordinal())\n                                .expect(\"Failed to get decimal\")\n                                .map(Box::new),\n                        ),\n\n                        #[cfg(feature = \"with-json\")]\n                        \"JSON\" => Value::Json(\n                            row.try_get::<Option<serde_json::Value>, _>(c.ordinal())\n                                .expect(\"Failed to get json\")\n                                .map(Box::new),\n                        ),","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_mysql.rs#L499-L535","documentation":"This is a panic raised by `.expect(\"Failed to get decimal\")` inside ProxyRow, which converts a sqlx MySQL row into SeaORM proxy values. When a column's type info says DECIMAL but `row.try_get::<Option<BigDecimal>>` fails (type mismatch between the declared column type and the actually decoded value, or an unexpected NULL/type encoding), the expect aborts the process with this message instead of returning an error.","triggerScenarios":"Reading a MySQL DECIMAL/NUMERIC column with the with-bigdecimal feature enabled while sqlx decodes a value that cannot be represented as Option<BigDecimal> — e.g. the column type_info reports DECIMAL but the underlying value is a string, an out-of-range number, or the driver returns an incompatible wire type.","commonSituations":"Decoding DECIMAL columns with unusual precision/scale, MySQL driver/driver-version mismatches where DECIMAL is returned as String, schema drift where a column changed type after the metadata was cached, or proxy-row conversions run against exotic column types (e.g. DECIMAL UNSIGNED or NEWDECIMAL labeled differently).","solutions":["Verify the column's actual MySQL type matches DECIMAL and its precision/scale is representable as BigDecimal; fix the schema or cast in SQL (CAST(col AS DECIMAL(m,d))).","Enable/disable the right feature: with-bigdecimal vs with-rust_decimal must match the crate your Cargo.toml actually uses for decimals.","Upgrade sea-orm and sqlx to matching, current versions so MySQL DECIMAL decoding is handled correctly.","Replace or wrap the proxy row conversion so a decode failure surfaces as a Result error instead of a panic (patch ProxyRow to use ok_or + From)."],"exampleFix":"// before (panics)\nrow.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())\n    .expect(\"Failed to get decimal\")\n// after (returns error)\nrow.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())\n    .map_err(|e| DbErr::Custom(format!(\"failed to decode decimal column {}: {e}\", c.name())))?","handlingStrategy":"validation","validationCode":"// Before converting rows, confirm the column type is decodable as BigDecimal\nlet info = c.type_info().name();\nif info != \"DECIMAL\" {\n    return Err(format!(\"unexpected column type {info} for decimal decoding\"));\n}\n// Optionally verify data: SELECT col IS NOT NULL, JSON/CAST checks in SQL","typeGuard":"fn is_decimal_column(c: &sqlx::mysql::MySqlColumn) -> bool {\n    c.type_info().name() == \"DECIMAL\"\n}","tryCatchPattern":null,"preventionTips":["Keep sea-orm and sqlx versions in lockstep in Cargo.toml","Match feature flags (with-bigdecimal vs with-rust_decimal) across all workspace crates","Avoid extreme DECIMAL precision/scale in MySQL schemas; cast in SQL when needed","Inspect schema drift after migrations before running proxy conversions","Prefer decoding paths that return Result over expect-based conversions when wrapping the driver yourself"],"tags":["mysql","decimal","decode","panic","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"}