{"record":{"id":"24ce227e62334de7","repo":"SeaQL/sea-orm","slug":"failed-to-get-year","errorCode":null,"errorMessage":"Failed to get year","messagePattern":"Failed to get year","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_mysql.rs","lineNumber":498,"sourceCode":"                        ),\n\n                        #[cfg(feature = \"with-chrono\")]\n                        \"DATETIME\" => Value::ChronoDateTime(\n                            row.try_get::<Option<chrono::NaiveDateTime>, _>(c.ordinal())\n                                .expect(\"Failed to get datetime\")\n                                .map(Box::new),\n                        ),\n                        #[cfg(all(feature = \"with-time\", not(feature = \"with-chrono\")))]\n                        \"DATETIME\" => Value::TimeDateTime(\n                            row.try_get::<Option<time::PrimitiveDateTime>, _>(c.ordinal())\n                                .expect(\"Failed to get datetime\")\n                                .map(Box::new),\n                        ),\n\n                        #[cfg(feature = \"with-chrono\")]\n                        \"YEAR\" => Value::ChronoDate(\n                            row.try_get::<Option<chrono::NaiveDate>, _>(c.ordinal())\n                                .expect(\"Failed to get year\")\n                                .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())","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_mysql.rs#L480-L516","documentation":"ProxyRow maps MySQL YEAR columns to a date Value and calls `row.try_get::<Option<chrono::NaiveDate>, _>()` with `expect(\"Failed to get year\")`. This panics when sqlx cannot decode the YEAR column's value into `chrono::NaiveDate`. It indicates the raw value of a column reported as YEAR does not meet decode expectations (e.g. it arrives as an integer or string rather than a date).","triggerScenarios":"A query against MySQL returns a YEAR column and sqlx fails to decode it as `chrono::NaiveDate` — commonly because the MySQL YEAR type is delivered over the wire as a 2-byte/integer value or short string ('2024') rather than a full date the NaiveDateTime/NaiveDate decoder accepts.","commonSituations":"Tables using MySQL's YEAR type (rare but real in legacy schemas); sqlx versions where YEAR decoding to NaiveDate is unsupported or broken; MariaDB returning YEAR with different wire encoding.","solutions":["Change the column type from YEAR to SMALLINT or DATE in the schema; YEAR is rarely worth its compatibility pitfalls.","Select with an explicit cast: `SELECT CAST(year_col AS DATE) FROM ...` or `CAST(year_col AS CHAR)` so the driver decodes a type it supports.","Upgrade/downgrade sqlx to a version with correct MySQL YEAR decoding, or file/check upstream sqlx issues for YEAR support.","Replace `.expect(...)` with error propagation in src/ (then run build-tools/make-sync.sh) so the failure becomes a `DbErr` instead of a panic."],"exampleFix":"// before: SELECT year_col FROM t;  -> panic in ProxyRow\n// after: cast in SQL so sqlx sees a supported type\nlet stmt = Statement::from_string(\n    DatabaseBackend::MySql,\n    \"SELECT CAST(year_col AS CHAR) AS year_col FROM t\",\n);","handlingStrategy":"validation","validationCode":"// Verify the column isn't MySQL YEAR before binding to NaiveDate decoding:\n-- SHOW COLUMNS FROM t LIKE 'year_col'; -- prefer SMALLINT/DATE over YEAR\n-- Or cast at query time: SELECT CAST(year_col AS CHAR) AS year_col FROM t;","typeGuard":null,"tryCatchPattern":"// YEAR decode panics aren't DbErr; cast columns in SQL instead:\nlet stmt = Statement::from_string(\n    DatabaseBackend::MySql,\n    \"SELECT CAST(year_col AS CHAR) AS year_col FROM t\",\n);\nlet rows = db.query_all(stmt)?;","preventionTips":["Avoid the MySQL YEAR type in new schemas; use SMALLINT or DATE.","Always cast YEAR columns (CAST AS CHAR/DATE) when selecting them through SeaORM's proxy.","Check sqlx release notes for MySQL YEAR decode support before upgrading.","Test queries against MariaDB if you support it — YEAR encoding can differ."],"tags":["mysql","year","chrono","decode","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"}