{"record":{"id":"785df825b7b4dbf8","repo":"SeaQL/sea-orm","slug":"cannot-unwrap-activevalue-notset-785df8","errorCode":null,"errorMessage":"Cannot unwrap ActiveValue::NotSet","messagePattern":"Cannot unwrap ActiveValue::NotSet","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/entity/active_value.rs","lineNumber":291,"sourceCode":"    }\n\n    /// Take ownership of the inner value, also setting self to `NotSet`\n    pub fn take(&mut self) -> Option<V> {\n        match std::mem::take(self) {\n            ActiveValue::Set(value) | ActiveValue::Unchanged(value) => Some(value),\n            ActiveValue::NotSet => None,\n        }\n    }\n\n    /// Get an owned value of the [ActiveValue]\n    ///\n    /// # Panics\n    ///\n    /// Panics if it is [ActiveValue::NotSet]\n    pub fn unwrap(self) -> V {\n        match self {\n            ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,\n            ActiveValue::NotSet => panic!(\"Cannot unwrap ActiveValue::NotSet\"),\n        }\n    }\n\n    /// Take ownership of the inner value, consuming self\n    pub fn into_value(self) -> Option<Value> {\n        match self {\n            ActiveValue::Set(value) | ActiveValue::Unchanged(value) => Some(value.into()),\n            ActiveValue::NotSet => None,\n        }\n    }\n\n    /// Wrap the [Value] into a `ActiveValue<Value>`\n    pub fn into_wrapped_value(self) -> ActiveValue<Value> {\n        match self {\n            Self::Set(value) => ActiveValue::set(value.into()),\n            Self::Unchanged(value) => ActiveValue::unchanged(value.into()),\n            Self::NotSet => ActiveValue::not_set(),\n        }","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/entity/active_value.rs#L273-L309","documentation":"ActiveValue::unwrap() extracts the inner Value from a Set or Unchanged ActiveValue. The library panics because NotSet means the field was never assigned a value, so there is nothing to unwrap. It is a deliberate programming-error signal, not a runtime failure.","triggerScenarios":"Calling .unwrap() on an ActiveValue that was never set — e.g. a freshly created ActiveModel field left at NotSet, or reading back a field skipped by NotSetErr/Unset().","commonSituations":"Copying values between models where some fields were never assigned; iterating model fields with the value() accessor and forgetting some are unset; converting an ActiveModel back to a Model with try_into_model missing so NotSet fields remain.","solutions":["Use try_get() / into_value() (fallible or Option-returning accessors) instead of unwrap()","Check the field with matches!(v, ActiveValue::Set(_) | ActiveValue::Unchanged(_)) before unwrapping","Ensure the field was explicitly .set(...) or .insert(...) on the ActiveModel before unwrapping","Convert with try_into_model() to get a Result instead of panicking"],"exampleFix":"// before\nlet v = user.name.unwrap();\n// after\nlet v = user.name.into_value().unwrap_or_default();","handlingStrategy":"type-guard","validationCode":"fn is_set<V>(v: &ActiveValue<V>) -> bool { matches!(v, ActiveValue::Set(_) | ActiveValue::Unchanged(_)) }","typeGuard":"fn try_value<V>(v: &ActiveValue<V>) -> Option<&V> { match v { ActiveValue::Set(x) | ActiveValue::Unchanged(x) => Some(x), _ => None } }","tryCatchPattern":"// Panics cannot be caught idiomatically; prefer fallible accessors\nlet v = user.name.into_value().ok_or_else(|| anyhow!(\"name not set\"))?;","preventionTips":["Prefer try_get/into_value over unwrap for ActiveValue access","Always set required fields on ActiveModel before save/read","Convert ActiveModel to Model with try_into_model to surface NotSet as Err"],"tags":["rust","panic","orm","active-model"],"backgroundTag":"internal-invariant-violation","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"}