SeaQL/sea-orm · error

Failed to get date

Error message

Failed to get date

What it means

Panic raised by `.expect()` in SeaORM's Postgres ProxyRow conversion: a column whose type string is `DATE` is decoded with sqlx as `Option<chrono::NaiveDate>` (chrono branch) or `Option<time::Date>` (time branch). If sqlx's decode returns an error — usually because the underlying Postgres type OID is not `date` — the panic message is "Failed to get date". It indicates the column metadata string and the actual wire type disagree.

Source

Thrown at src/driver/sqlx_postgres.rs:759

                            feature = "postgres-array"
                        ))]
                        "TIMESTAMP[]" => Value::Array(
                            sea_query::ArrayType::TimeDateTime,
                            row.try_get::<Option<Vec<time::PrimitiveDateTime>>, _>(c.ordinal())
                                .expect("Failed to get timestamp array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::TimeDateTime(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        #[cfg(feature = "with-chrono")]
                        "DATE" => Value::ChronoDate(
                            row.try_get::<Option<chrono::NaiveDate>, _>(c.ordinal())
                                .expect("Failed to get date"),
                        ),
                        #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
                        "DATE" => Value::TimeDate(
                            row.try_get::<Option<time::Date>, _>(c.ordinal())
                                .expect("Failed to get date"),
                        ),

                        #[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
                        "DATE[]" => Value::Array(
                            sea_query::ArrayType::ChronoDate,
                            row.try_get::<Option<Vec<chrono::NaiveDate>>, _>(c.ordinal())
                                .expect("Failed to get date array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::ChronoDate(Some(val)))
                                            .collect(),
                                    )

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Inspect the column's real type and make it exactly `date` (or cast: `SELECT d::date FROM ...`).
  2. Enable `with-chrono` (or `with-time`) on sea-orm so the matching decode impl is compiled.
  3. Update sea-orm/sqlx to a compatible pair where the date decode is supported for your Postgres version.
  4. If the value may be NULL or non-date, avoid the proxy path or select as text and parse manually.

Example fix

// before: col is actually timestamptz, decode to NaiveDate panics
let rows = stmt.map(|row| row.into_proxy_row()).await?;

// after: force the date type in SQL
let stmt = Statement::from_string(
    db.get_database_backend(),
    "SELECT birthday::date AS birthday FROM users",
);
Defensive patterns

Strategy: validation

Validate before calling

let ty: Option<String> = sqlx::query_scalar(
    "SELECT data_type FROM information_schema.columns WHERE table_name=$1 AND column_name=$2")
    .bind("users").bind("birthday").fetch_optional(db).await?;
assert_eq!(ty.as_deref(), Some("date"));

Type guard

fn is_pg_date(data_type: &str) -> bool { data_type.eq_ignore_ascii_case("date") }

Try / catch

// expect() panics; prefer validating first. If unavoidable:
let decoded = std::panic::catch_unwind(AssertUnwindSafe(|| row.into_proxy_row()));
if decoded.is_err() { eprintln!("DATE column type mismatch — check schema"); }

Prevention

When it happens

Trigger: Selecting a DATE column through ProxyRow where the value cannot decode to `NaiveDate`/`time::Date` — e.g. the column is actually `timestamptz`, `timestamp`, or a custom domain over date, or the chrono/time feature required for the decode impl is not enabled as compiled.

Common situations: Views or CTEs that return date-valued expressions with inferred non-date types; DB schema changed a column from DATE to TIMESTAMP; mixing feature flags so neither `with-chrono` nor `with-time` decode impls line up with the branch chosen by the type string.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/d7609c60dc74a47b. Report an issue: GitHub.