{"record":{"id":"1fcdf790ad043a83","repo":"SeaQL/sea-orm","slug":"not-proxy-connection-1fcdf7","errorCode":null,"errorMessage":"Not proxy connection","messagePattern":"Not proxy connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/database/db_connection.rs","lineNumber":610,"sourceCode":"            .as_mock_connection()\n            .get_mocker_mutex()\n            .lock()\n            .expect(\"Fail to acquire mocker\");\n        mocker.drain_transaction_log()\n    }\n}\n\n#[cfg(feature = \"proxy\")]\nimpl DatabaseConnection {\n    /// Generate a database connection for testing the Proxy database\n    ///\n    /// # Panics\n    ///\n    /// Panics if [DbConn] is not a proxy connection.\n    pub fn as_proxy_connection(&self) -> &crate::ProxyDatabaseConnection {\n        match &self.inner {\n            DatabaseConnectionType::ProxyDatabaseConnection(proxy_conn) => proxy_conn,\n            _ => panic!(\"Not proxy connection\"),\n        }\n    }\n}\n\n#[cfg(feature = \"rbac\")]\nimpl DatabaseConnection {\n    /// Load RBAC data from the same database as this connection and setup RBAC engine.\n    /// If the RBAC engine already exists, it will be replaced.\n    pub async fn load_rbac(&self) -> Result<(), DbErr> {\n        self.load_rbac_from(self).await\n    }\n\n    /// Load RBAC data from the given database connection and setup RBAC engine.\n    /// This could be from another database.\n    pub async fn load_rbac_from(&self, db: &DbConn) -> Result<(), DbErr> {\n        let engine = crate::rbac::RbacEngine::load_from(db).await?;\n        self.rbac.replace(engine);\n        Ok(())","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/database/db_connection.rs#L592-L628","documentation":"`DatabaseConnection::as_proxy_connection()` downcasts the connection to a `ProxyDatabaseConnection`. A proxy connection exists only when the connection was created from a `ProxyDatabaseConnector::wrap(...)` (or equivalent proxy setup); any other inner `DatabaseConnectionType` triggers this panic. It exists so proxy-specific query routing code can safely obtain the proxy handle.","triggerScenarios":"Calling `db.as_proxy_connection()` on a `DatabaseConnection` obtained from `Database::connect()` (sqlx mysql/postgres/sqlite) or from a `MockDatabase`, i.e. any connection not wrapped via the proxy connector; invoking proxy-only query paths when the `proxy` feature connection was never constructed.","commonSituations":"Using the RBAC/seaography proxy plumbing against a normally connected database; enabling the `proxy` feature but forgetting to wrap the connection with `ProxyDatabaseConnector`; tests that share a `DatabaseConnection` between mock and proxy code paths.","solutions":["Create the connection through the proxy connector: `let conn = ProxyDatabaseConnector::wrap(MyProxy { ... });` and use that `DatabaseConnection` wherever `as_proxy_connection()` is called.","Ensure the `proxy` feature is enabled and that the code path constructing the DB handle actually performs the proxy wrap, not `Database::connect`.","Guard the call: only call `as_proxy_connection()` behind a check/`#[cfg(feature = \"proxy\")]` branch that also verifies the connection kind.","If you need both, keep separate connections — a real one for normal queries and a wrapped proxy one for proxy/RBAC paths."],"exampleFix":"// before\nlet db = Database::connect(\"mysql://localhost/app\").await?;\nlet proxy = db.as_proxy_connection(); // panics: not a proxy connection\n\n// after\nlet db = ProxyDatabaseConnector::wrap(MyAppProxy::default());\nlet proxy = db.as_proxy_connection(); // ok","handlingStrategy":"type-guard","validationCode":"// Only build the handle through the proxy connector\nlet db = ProxyDatabaseConnector::wrap(MyProxy::default());\nlet _proxy = db.as_proxy_connection(); // safe by construction","typeGuard":"struct ProxyDb { conn: DatabaseConnection } // conn is ALWAYS ProxyDatabaseConnector::wrap(...)\nimpl ProxyDb {\n    fn wrap(p: impl Proxy) -> Self { Self { conn: ProxyDatabaseConnector::wrap(p) } }\n    fn proxy(&self) -> &ProxyDatabaseConnection { self.conn.as_proxy_connection() }\n}","tryCatchPattern":"// panic! is not catchable in Rust; enforce at construction time\nfn ensure_proxy(db: &DatabaseConnection) -> Option<&ProxyDatabaseConnection> {\n    // only call as_proxy_connection in paths that built the conn via ProxyDatabaseConnector\n    None\n}","preventionTips":["Always construct proxy-mode handles via ProxyDatabaseConnector::wrap; never call as_proxy_connection on connections from Database::connect.","Enable the `proxy` feature and verify the wrap happens before any RBAC/proxy query path runs.","Keep proxy connections in their own dedicated type/field so mixing with real DatabaseConnection values is a compile-time (type-level) mistake instead of a panic."],"tags":["panic","proxy-database","type-mismatch","feature-flag","seaorm"],"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"}