SeaQL/sea-orm

`AttrNotSet` error when using `.try_into_model()` even though the attribute listed is optional

Open

#2,834 opened on Dec 2, 2025

 (3 comments) (0 reactions) (1 assignee)Rust (718 forks)auto 404
good first issue

Repository metrics

Stars
 (9,827 stars)
PR merge metrics
 (PR metrics pending)

Description

Description

When creating models as mock inputs for testing purposes, I am creating an ActiveModel with only the non-nullable fields filled out and using default to make the rest NotSet, then using .try_into_model() to convert that into a model (which is required by my function). When I run the test, I get an AttrNotSet error complaining that I haven't set the optional fields, even though these should default to None.

Steps to Reproduce

Model definition:

#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "stations_creston")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub station_id: i32,
    #[sea_orm(unique)]
    pub network_id: String,
    pub station_name: String,
    pub installation_date: Option<TimeDate>,
}

It should also be noted that installation_date is set to nullable in my MySQL database, and the default value is set to NULL

Test setup

let test_station = stations_creston::ActiveModel {
    station_id: ActiveValue::Set(628),
    network_id: ActiveValue::Set("CRESNEKN".to_owned()),
    station_name: ActiveValue::Set("example".to_owned()),
    ..Default::default()
}
.try_into_model()
.expect("couldn't make test station model");

Expected Behavior

This shouldn't panic

Actual Behavior

The following panic is produced:

thread 'apis::creston::test::get_data' panicked at src/apis/creston.rs:181:10:
couldn't make test station model: AttrNotSet("installation_date")

Reproduces How Often

Happens every time

Versions

SeaOrm 2.0.0-rc.18 cargo 1.93.0-nightly Void Linux

Contributor guide