{"record":{"id":"f04f1f646410d2e3","repo":"SeaQL/sea-orm","slug":"failed-to-get-datetime-f04f1f","errorCode":null,"errorMessage":"Failed to get datetime","messagePattern":"Failed to get datetime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_mysql.rs","lineNumber":493,"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":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_mysql.rs#L475-L511","documentation":"ProxyRow panicked while converting a MySQL DATETIME column with `with-chrono` enabled: `row.try_get::<Option<chrono::NaiveDateTime>, _>(c.ordinal())` errored and `.expect(\"Failed to get datetime\")` panicked. sqlx could not decode the value as chrono::NaiveDateTime, so the value does not match the declared DATETIME type.","triggerScenarios":"Reading a DATETIME column containing the zero datetime '0000-00-00 00:00:00', values outside chrono's supported range, or expressions (NOW(), DATE_SUB aliases) whose runtime type or format diverges from the declared DATETIME.","commonSituations":"Zero datetimes in legacy rows from non-strict servers; timezone-misconfigured servers returning stringified values; schema drift where a column was altered but cached metadata/stale prepared statements disagree.","solutions":["Purge or NULL zero datetimes: UPDATE t SET dt = NULL WHERE dt = '0000-00-00 00:00:00'; enable strict SQL mode thereafter.","NULLIF or CAST the offending expression in SQL so the wire value is a proper DATETIME.","Confirm the effective column/expression type via information_schema or EXPLAIN, especially for views and UNIONs.","Check that you are not inserting invalid values from your own writes; validate on the Rust side before insert.","Upgrade sea-orm and sqlx together if decode strictness changed with a version bump."],"exampleFix":"// before — zero datetime row panics ProxyRow\nlet orders = Order::find().all(db).await?;\n\n// after — sanitize at query time\nlet orders = Order::find()\n    .from_raw_sql(Statement::from_sql_and_values(\n        DbBackend::MySql,\n        \"SELECT id, NULLIF(shipped_at, '0000-00-00 00:00:00') AS shipped_at FROM orders\",\n        [],\n    ))\n    .all(db).await?;","handlingStrategy":"validation","validationCode":"// Pre-flight zero-datetime scan\n// SELECT COUNT(*) FROM orders WHERE shipped_at = '0000-00-00 00:00:00'\nif count_zero_datetimes(db, \"orders\", \"shipped_at\").await? > 0 {\n    bail!(\"zero datetimes present; NULL them before querying\");\n}","typeGuard":"fn valid_mysql_datetime(s: &str) -> bool {\n    s != \"0000-00-00 00:00:00\" && chrono::NaiveDateTime::parse_from_str(s, \"%Y-%m-%d %H:%M:%S\").is_ok()\n}","tryCatchPattern":"let dt = std::panic::catch_unwind(|| row.try_decode_datetime(ordinal)).ok().flatten();\nlet dt = dt.or_else(|| load_datetime_as_string_then_parse(ordinal));","preventionTips":["Strict mode on all MySQL servers to ban zero datetimes","NULLIF zero datetimes in legacy raw queries","CAST NOW()/DATE_SUB-style expressions to DATETIME when aliased","Validate datetime strings on the Rust side before INSERT","Upgrade sea-orm and sqlx as a unit"],"tags":["mysql","sqlx","datetime","chrono","panic","decode"],"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"}