{"record":{"id":"edd303d4dcf28275","repo":"SeaQL/sea-orm","slug":"should-only-have-one-owner-edd303","errorCode":null,"errorMessage":"Should only have one owner","messagePattern":"Should only have one owner","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/database/sea_schema_shim.rs","lineNumber":83,"sourceCode":"\nfn map_result(result: Result<Vec<QueryResult>, DbErr>) -> Result<Vec<SqlxRow>, SqlxError> {\n    match result {\n        Ok(rows) => Ok(rows\n            .into_iter()\n            .filter_map(|r| match r.row {\n                #[cfg(feature = \"sqlx-mysql\")]\n                QueryResultRow::SqlxMySql(r) => Some(SqlxRow::MySql(r)),\n                #[cfg(feature = \"sqlx-postgres\")]\n                QueryResultRow::SqlxPostgres(r) => Some(SqlxRow::Postgres(r)),\n                #[cfg(feature = \"sqlx-sqlite\")]\n                QueryResultRow::SqlxSqlite(r) => Some(SqlxRow::Sqlite(r)),\n                #[allow(unreachable_patterns)]\n                _ => None,\n            })\n            .collect()),\n        Err(err) => Err(match err {\n            DbErr::Conn(RuntimeErr::SqlxError(err)) => {\n                Arc::into_inner(err).expect(\"Should only have one owner\")\n            }\n            DbErr::Exec(RuntimeErr::SqlxError(err)) => {\n                Arc::into_inner(err).expect(\"Should only have one owner\")\n            }\n            DbErr::Query(RuntimeErr::SqlxError(err)) => {\n                Arc::into_inner(err).expect(\"Should only have one owner\")\n            }\n            _ => SqlxError::AnyDriverError(Box::new(err)),\n        }),\n    }\n}\n","sourceCodeStart":65,"sourceCodeEnd":95,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/database/sea_schema_shim.rs#L65-L95","documentation":"This is the sqlx counterpart of the rusqlite shim panic: in `sea_schema_shim.rs`, `map_result` calls `Arc::into_inner(err).expect(\"Should only have one owner\")` on `DbErr::Conn(RuntimeErr::SqlxError(err))`. `Arc::into_inner` only succeeds when the error `Arc` has exactly one owner; otherwise it returns `None` and the `expect` panics. The library assumes sqlx errors are uniquely owned when converting a connection failure into a `sqlx::Error` for sea_schema.","triggerScenarios":"`query_all`/`query_all_raw` through the sea_schema `Connection` impl fails with `DbErr::Conn(RuntimeErr::SqlxError(...))` while another clone of the `Arc<sqlx::Error>` exists at mapping time.","commonSituations":"Hit during schema discovery over a sqlx-backed connection (MySQL/Postgres/SQLite) when the connection itself fails (disconnect, pool closed) and some layer (logging, pooling, retry logic) retains a clone of the error. Treat it as a library invariant bug rather than a user misconfiguration.","solutions":["Upgrade sea-orm/sea-schema to the latest compatible versions.","Ensure no custom middleware clones `DbErr` (and thus the inner `Arc<sqlx::Error>`) before the shim maps it.","Patch the shim defensively: use `Arc::try_unwrap` with an `SqlxError::AnyDriverError` fallback instead of `expect`.","File an upstream issue with the connection failure and backtrace if it occurs with stock usage."],"exampleFix":"// before\nDbErr::Conn(RuntimeErr::SqlxError(err)) => {\n    Arc::into_inner(err).expect(\"Should only have one owner\")\n}\n// after\nDbErr::Conn(RuntimeErr::SqlxError(err)) => {\n    Arc::try_unwrap(err)\n        .unwrap_or_else(|e| SqlxError::AnyDriverError(Box::new(DbErr::Conn(RuntimeErr::SqlxError(e)))))\n}","handlingStrategy":"try-catch","validationCode":"// Ensure the sqlx connection is alive before schema discovery\nconn.ping().map_err(|e| eprintln!(\"backend unreachable: {e}\"))?;","typeGuard":"fn conn_err_unique(err: &DbErr) -> bool {\n    matches!(err, DbErr::Conn(RuntimeErr::SqlxError(e))) && Arc::strong_count(e) == 1\n}","tryCatchPattern":"std::panic::catch_unwind(AssertUnwindSafe(|| discovery.query_all(select)))\n    .map_err(|_| anyhow!(\"panic in sea_schema sqlx shim\"))?;","preventionTips":["Keep sqlx and sea-orm on compatible versions","Avoid middleware that clones sqlx errors before the shim maps them","Use catch_unwind around schema discovery in fault-tolerant services","If it reproduces on stock usage, file an upstream bug with a backtrace"],"tags":["panic","arc","sqlx","error-mapping","internal"],"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"}