`AttrNotSet` error when using `.try_into_model()` even though the attribute listed is optional
@PacificBird is already working on this.
Since Dec 18, 2025.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 734
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.