{"record":{"id":"cb1df1f597588a2c","repo":"SeaQL/sea-orm","slug":"failed-to-get-datetime","errorCode":null,"errorMessage":"Failed to get datetime","messagePattern":"Failed to get datetime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_mysql.rs","lineNumber":485,"sourceCode":"                        ),\n\n                        #[cfg(feature = \"with-chrono\")]\n                        \"TIME\" => Value::ChronoTime(\n                            row.try_get::<Option<chrono::NaiveTime>, _>(c.ordinal())\n                                .expect(\"Failed to get time\")\n                                .map(Box::new),\n                        ),\n                        #[cfg(all(feature = \"with-time\", not(feature = \"with-chrono\")))]\n                        \"TIME\" => Value::TimeTime(\n                            row.try_get::<Option<time::Time>, _>(c.ordinal())\n                                .expect(\"Failed to get time\")\n                                .map(Box::new),\n                        ),\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())","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_mysql.rs#L467-L503","documentation":"This panic comes from an `expect(\"Failed to get datetime\")` inside ProxyRow's MySQL driver conversion. When the column's declared type is DATETIME, the driver calls `row.try_get::<Option<chrono::NaiveDateTime>, _>()` and panics if sqlx cannot decode the raw value into that Rust type. It means the database returned a DATETIME column whose underlying value does not satisfy sqlx's decode requirements (wrong sqlx type, zero-date, or a format the decoder rejects).","triggerScenarios":"Executing a query via the sync proxy against MySQL where a column typed DATETIME contains a value sqlx cannot decode into `chrono::NaiveDateTime` — e.g. MySQL's zero date '0000-00-00 00:00:00', an invalid/NULL-encoded value in a NOT NULL branch, or a column reported as DATETIME but holding a different wire type. The panic occurs inside `crate::ProxyRow` while converting the raw sqlx row into SeaORM Values.","commonSituations":"Connecting to a MySQL/MariaDB server with `NO_ZERO_DATE` not enforced (legacy data with zero dates); MariaDB versions that encode DATETIME differently than MySQL; schema drift where a column was ALTERed to DATETIME but holds legacy values; using sqlx's MySQL driver against a proxy or non-MySQL backend that misreports column types.","solutions":["Enable MySQL strict mode / set `sql_mode` to reject zero dates and clean or migrate rows containing '0000-00-00 00:00:00'.","Verify the column is a genuine MySQL DATETIME (`SHOW COLUMNS FROM ...`) and not a drifted/aliased type; fix the schema or cast in the query.","Use a MariaDB-compatible sqlx driver setting or upgrade sqlx if connecting to MariaDB with known DATETIME encoding differences.","Prefer `try_get` with proper error propagation instead of `.expect(...)` in the driver code so decode failures become normal errors (upstream fix in src/ then regenerate sea-orm-sync)."],"exampleFix":"// before: query hits a legacy zero-date row and panics\nlet rows = proxy.query_all(statement)?;\n\n// after: sanitize data server-side first\n-- ALTER TABLE t MODIFY col DATETIME NULL;\n-- UPDATE t SET col = NULL WHERE col = '0000-00-00 00:00:00';","handlingStrategy":"validation","validationCode":"// Sanitize zero/invalid DATETIME rows before querying\n-- SELECT COUNT(*) FROM t WHERE col = '0000-00-00 00:00:00' OR col IS NULL; -- must be 0\n-- Ensure sql_mode includes NO_ZERO_DATE/STRICT_TRANS_TABLES:\n-- SELECT @@sql_mode;","typeGuard":null,"tryCatchPattern":"// The panic is not catchable as a DbErr; avoid it by pre-validating data.\n// Optionally isolate risky reads and check column types first:\nlet cols = db.query_all(Statement::from_string(\n    DatabaseBackend::MySql,\n    format!(\"SHOW COLUMNS FROM {}\", table),\n))?; // verify type == \"datetime\" and no legacy values\nlet rows = db.query_all(statement)?;","preventionTips":["Run MySQL in strict mode with NO_ZERO_DATE so invalid DATETIMEs can't be stored.","Audit legacy tables for '0000-00-00 00:00:00' values before reading them with SeaORM.","Keep column types aligned with what the model expects; re-check after ALTERs.","Prefer MariaDB/MySQL versions and sqlx versions with matching DATETIME encoding support."],"tags":["mysql","datetime","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"}