-
-
Notifications
You must be signed in to change notification settings - Fork 645
Open
Open
Feature
Copy link
Labels
good first issueGood for newcomersGood for newcomers
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
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers