SeaQL/sea-orm · critical

Failed to get time

Error message

Failed to get time

What it means

This panic happens in the SQLite driver when a column is reported as type TIME and the with-chrono feature is on. The driver calls row.try_get::<Option<NaiveTime>, _>(ordinal).expect("Failed to get time") and panics because sqlx could not decode the stored value into a chrono NaiveTime. It signals that the column's declared type and its actual stored representation are inconsistent.

Source

Thrown at sea-orm-sync/src/driver/sqlx_sqlite.rs:485

                                    .map(Box::new),
                            )
                        }
                        #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
                        "DATE" => {
                            use time::Date;
                            Value::TimeDate(
                                row.try_get::<Option<Date>, _>(c.ordinal())
                                    .expect("Failed to get date")
                                    .map(Box::new),
                            )
                        }

                        #[cfg(feature = "with-chrono")]
                        "TIME" => {
                            use chrono::NaiveTime;
                            Value::ChronoTime(
                                row.try_get::<Option<NaiveTime>, _>(c.ordinal())
                                    .expect("Failed to get time")
                                    .map(Box::new),
                            )
                        }
                        #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
                        "TIME" => {
                            use time::Time;
                            Value::TimeTime(
                                row.try_get::<Option<Time>, _>(c.ordinal())
                                    .expect("Failed to get time")
                                    .map(Box::new),
                            )
                        }

                        _ => unreachable!("Unknown column type: {}", c.type_info().name()),
                    },
                )
            })
            .collect(),

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Inspect and fix the stored values to valid 'HH:MM:SS' time strings decodable as NaiveTime.
  2. Change the column's declared type (e.g. to TEXT) so the driver stops attempting TIME decoding, or remap the entity field type to String and parse manually.
  3. Rebuild the table through SeaORM migrations with the correct column type and reimport clean data.
  4. Check whether values were written as full timestamps and either move them to a DATETIME column or strip the date part before insert.

Example fix

// before: TIME column contains a full timestamp
// sqlite> SELECT start_t FROM shifts;  => '2026-09-10 08:30:00'

// after: store only the time component
// sqlite> UPDATE shifts SET start_t = '08:30:00' WHERE id = 1;
Defensive patterns

Strategy: validation

Validate before calling

// Check TIME columns contain only time-of-day strings before ORM reads
let bad: Vec<String> = sqlx::query_scalar(
    "SELECT start_t FROM shifts WHERE start_t NOT GLOB '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]*'")
    .fetch_all(&pool).await?;
assert!(bad.is_empty(), "malformed TIME values: {:?}", bad);

Type guard

fn parses_as_naive_time(s: &str) -> bool {
    chrono::NaiveTime::parse_from_str(s, "%H:%M:%S").is_ok()
}

Try / catch

// Isolate the panic on a thread since expect() aborts the normal error path
let res = std::thread::spawn(move || sync_query()).join();
match res {
    Ok(rows) => rows,
    Err(_) => Err(Error::DbErrCustom("TIME column decode panic - stored value is not a valid NaiveTime".into())),
}

Prevention

When it happens

Trigger: Selecting from a SQLite table whose TIME column holds a value sqlx cannot decode as NaiveTime — e.g. '25:99:00', a full timestamp string in a TIME column, or a numeric value stored by another tool under TIME affinity.

Common situations: Hand-edited or imported SQLite data with malformed time strings; storing DATETIME values in TIME-typed columns; older schemas written by a different SQLite driver or ORM with a different time encoding.

Related errors


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