{"record":{"id":"deb6fbf044cc9e38","repo":"SeaQL/sea-orm","slug":"called-hasone-unwrap-on-a-loaded-none-valu","errorCode":null,"errorMessage":"called `HasOne::unwrap()` on a `Loaded(None)` value","messagePattern":"called `HasOne::unwrap\\(\\)` on a `Loaded\\(None\\)` value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/entity/compound/has_one.rs","lineNumber":78,"sourceCode":"        match self {\n            Self::Loaded(Some(model)) => Some(*model),\n            Self::Unloaded | Self::Loaded(None) => None,\n        }\n    }\n\n    /// Take ownership of the contained Model, if loaded, leaving `Unloaded` in place.\n    pub fn take(&mut self) -> Option<E::ModelEx> {\n        std::mem::take(self).into_option()\n    }\n\n    /// # Panics\n    ///\n    /// Panics if called on an `Unloaded` or `Loaded(None)` value.\n    pub fn unwrap(self) -> E::ModelEx {\n        match self {\n            Self::Loaded(Some(model)) => *model,\n            Self::Unloaded => panic!(\"called `HasOne::unwrap()` on an `Unloaded` value\"),\n            Self::Loaded(None) => panic!(\"called `HasOne::unwrap()` on a `Loaded(None)` value\"),\n        }\n    }\n}\n\nimpl<E> HasOne<E>\nwhere\n    E: EntityTrait,\n    E::ActiveModelEx: From<E::ModelEx>,\n{\n    pub fn into_active_model(self) -> ActiveHasOne<E> {\n        match self {\n            Self::Loaded(Some(model)) => ActiveHasOne::set(Some(*model)),\n            Self::Unloaded | Self::Loaded(None) => ActiveHasOne::NotSet,\n        }\n    }\n}\n\nimpl<E: EntityTrait> From<HasOne<E>> for Option<Box<E::ModelEx>> {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/entity/compound/has_one.rs#L60-L96","documentation":"unwrap() was called on a Loaded(None) HasOne: the relation was eagerly loaded and the query ran, but no related row exists in the database (the FK points nowhere or the target was deleted). unwrap() deliberately refuses to invent a value for an absent related row, so it panics; callers must treat 'no related row' as a normal, expected outcome.","triggerScenarios":"Thrown at sea-orm-sync/src/entity/compound/has_one.rs:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Treat a missing related row as valid: use into_option() or take() and handle the None case.","If the row is required, validate the foreign key / restore the missing target row rather than unwrapping blindly.","Use try_as_ref-style or match-based access so a dangling FK does not crash the request."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}