{"record":{"id":"ef22616f1e5b5b6f","repo":"SeaQL/sea-orm","slug":"failed-to-set-value-for-e","errorCode":null,"errorMessage":"Failed to set value for {:?}: {e:?}","messagePattern":"Failed to set value for (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/entity/active_model.rs","lineNumber":44,"sourceCode":"///   from `UPDATE`.\n///\n/// This makes ActiveModel ideal for partial updates: only the columns you\n/// touch end up in the generated `UPDATE`.\npub trait ActiveModelTrait: Clone + Debug {\n    /// The [`EntityTrait`] this ActiveModel belongs to.\n    type Entity: EntityTrait;\n\n    /// Take the [`ActiveValue`] of a column, leaving it as `NotSet`.\n    fn take(&mut self, c: <Self::Entity as EntityTrait>::Column) -> ActiveValue<Value>;\n\n    /// Read the [`ActiveValue`] of a column.\n    fn get(&self, c: <Self::Entity as EntityTrait>::Column) -> ActiveValue<Value>;\n\n    /// Set one column to `Set(v)`. Panics on type mismatch; prefer\n    /// [`try_set`](Self::try_set) when the value comes from untrusted input.\n    fn set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value) {\n        self.try_set(c, v)\n            .unwrap_or_else(|e| panic!(\"Failed to set value for {:?}: {e:?}\", c.as_column_ref()))\n    }\n\n    /// Set one column to `Set(v)` only if `v` differs from the current value,\n    /// avoiding spurious `UPDATE` rewrites. Panics on type mismatch.\n    fn set_if_not_equals(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value);\n\n    /// Set one column to `Set(v)`, returning an error on type mismatch.\n    fn try_set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value) -> Result<(), DbErr>;\n\n    /// Mark a column as `NotSet` so it is omitted from the next `INSERT` or\n    /// `UPDATE`.\n    fn not_set(&mut self, c: <Self::Entity as EntityTrait>::Column);\n\n    /// `true` if the column is currently in the `NotSet` state.\n    fn is_not_set(&self, c: <Self::Entity as EntityTrait>::Column) -> bool;\n\n    /// A fresh ActiveModel with every column `NotSet`.\n    fn default() -> Self;","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/entity/active_model.rs#L26-L62","documentation":"`ActiveModel::set` panics when the provided value cannot be converted into the column's expected type via `try_set`. The library deliberately panics (instead of returning a Result) because `set` is meant for trusted, compile-time-checked values; the message includes the column reference and the underlying conversion error.","triggerScenarios":"Calling `model.set(user::COLUMN.name, wrong_typed_value)` where `v`'s Rust type does not match the column type — e.g. passing an `i32` where the column is `String`, a `String` where a `DateTime`/decimal is expected, or `None` into a non-optional column. Also reached from `set_from_json` when a JSON field's value does not fit the column's type.","commonSituations":"Deserializing user-supplied JSON into an ActiveModel (`set_from_json`) with mismatched field types; refactoring a column type (int -> bigint, NaiveDateTime -> DateTime) without updating call sites; passing Option into a non-null column.","solutions":["Use `try_set` instead of `set` for untrusted values and handle the returned Result.","Fix the value type at the call site so it matches the entity column type declared in the Model.","For JSON input, validate/coerce fields with `set_from_json`'s fallible counterpart or validate the payload schema first.","If a column type changed, regenerate/review the entity definition and update all setters."],"exampleFix":"// before\nactive.set(user::COLUMN.age, json_value.as_str().unwrap().to_string()); // wrong type\n// after\nactive.try_set(user::COLUMN.age, json_value.as_i64().ok_or(...)? as i32)\n    .expect(\"age must be i32\");","handlingStrategy":"validation","validationCode":"// Validate/coerce untrusted values before set\nfn coerce_age(v: &serde_json::Value) -> Option<i32> { v.as_i64().map(|n| n as i32) }\n// or prefer the fallible API\nactive.try_set(user::COLUMN.age, value)?;","typeGuard":"fn is_settable<T: IntoActiveValue<V>, V>(v: &T) -> bool { true } // rely on try_set's Result instead\nfn try_set_guard<AM: ActiveModelTrait>(am: &mut AM, c: AM::Column, v: serde_json::Value) -> bool { am.try_set_from_json(c, v).is_ok() }","tryCatchPattern":"// set() panics; use try_set and handle the error\nmatch active.try_set(user::COLUMN.email, value) {\n    Ok(()) => {},\n    Err(e) => eprintln!(\"invalid value for email: {e:?}\"),\n}","preventionTips":["Use try_set for any value from untrusted input (JSON, user requests)","Keep column types in sync with entity definitions after migrations","Validate payload schemas before set_from_json"],"tags":["type-mismatch","panic","active-model","setter"],"backgroundTag":"type-mismatch","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}