{"record":{"id":"ca417b186bc432b8","repo":"SeaQL/sea-orm","slug":"cannot-borrow-activevalue-notset-ca417b","errorCode":null,"errorMessage":"Cannot borrow ActiveValue::NotSet","messagePattern":"Cannot borrow ActiveValue::NotSet","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/entity/active_value.rs","lineNumber":612,"sourceCode":"            ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,\n            ActiveValue::NotSet => None,\n        }\n    }\n}\n\nimpl<V> std::convert::AsRef<V> for ActiveValue<V>\nwhere\n    V: Into<Value>,\n{\n    /// # Panics\n    ///\n    /// Panics if it is [ActiveValue::NotSet].\n    ///\n    /// See [ActiveValue::try_as_ref] for a fallible non-panicking version.\n    fn as_ref(&self) -> &V {\n        match self {\n            ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,\n            ActiveValue::NotSet => panic!(\"Cannot borrow ActiveValue::NotSet\"),\n        }\n    }\n}\n\nimpl<V> PartialEq for ActiveValue<V>\nwhere\n    V: Into<Value> + std::cmp::PartialEq,\n{\n    fn eq(&self, other: &Self) -> bool {\n        match (self, other) {\n            (ActiveValue::Set(l), ActiveValue::Set(r)) => l == r,\n            (ActiveValue::Unchanged(l), ActiveValue::Unchanged(r)) => l == r,\n            (ActiveValue::NotSet, ActiveValue::NotSet) => true,\n            _ => false,\n        }\n    }\n}\n","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/entity/active_value.rs#L594-L630","documentation":"ActiveValue<V>::as_ref() borrows the inner value only when the value is Set or Unchanged; the reference cannot exist for the NotSet variant because no value is stored. The panic is the deliberately non-fallible counterpart to try_as_ref, fired when the caller borrowed an ActiveValue that was never assigned (still NotSet), e.g. reading a field of a freshly built ActiveModel before setting it.","triggerScenarios":"Calling .as_ref() (directly or via generic code taking &V) on an ActiveValue in the NotSet state.","commonSituations":"Generic helper functions borrowing ActiveValue fields on partially-filled ActiveModels; comparing or hashing fields where some were never set.","solutions":["Use try_as_ref() and handle the Err(NotSet) case instead of as_ref().","Ensure the field is set (Set/Unchanged) before borrowing — check with is_set()/is_not_set() or set a default first.","For optional access, use the existing opt accessor which returns Option<&V> and yields None for NotSet."],"exampleFix":"// before\nlet v = user.email.as_ref();\n// after\nlet v = user.email.try_as_ref().expect(\"email must be set\");","handlingStrategy":"type-guard","validationCode":"if !matches!(av, ActiveValue::Set(_) | ActiveValue::Unchanged(_)) { return Err(\"field not set\"); }","typeGuard":"fn try_borrow<V>(v: &ActiveValue<V>) -> Option<&V> { v.try_as_ref().ok() }","tryCatchPattern":"// Prefer try_as_ref\nlet v = user.email.try_as_ref().map_err(|_| anyhow!(\"email not set\"))?;","preventionTips":["Use try_as_ref in generic code instead of as_ref","Default-fill optional fields before borrowing","Audit generic helpers that take &ActiveValue"],"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"}