{"record":{"id":"76d0734569ffb25e","repo":"SeaQL/sea-orm","slug":"not-proxy-connection","errorCode":null,"errorMessage":"Not proxy connection","messagePattern":"Not proxy connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/database/db_connection.rs","lineNumber":564,"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 fn load_rbac(&self) -> Result<(), DbErr> {\n        self.load_rbac_from(self)\n    }\n\n    /// Load RBAC data from the given database connection and setup RBAC engine.\n    /// This could be from another database.\n    pub fn load_rbac_from(&self, db: &DbConn) -> Result<(), DbErr> {\n        let engine = crate::rbac::RbacEngine::load_from(db)?;\n        self.rbac.replace(engine);\n        Ok(())","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/database/db_connection.rs#L546-L582","documentation":"as_proxy_connection() unwraps the inner connection enum to a ProxyDatabaseConnection. It panics for any connection that is not a proxy connection (sqlx pools, rusqlite, mock, or Disconnected). The proxy backend is a specialized feature, so the API assumes callers deliberately created one.","triggerScenarios":"Calling as_proxy_connection() on a connection not created via ProxyDatabaseConnection / DatabaseConnectionType::ProxyDatabaseConnection, e.g. a normal connect() result or a mock connection.","commonSituations":"Mixing up proxy and mock test helpers; forgetting to wire the app to use the proxy backend in integration tests; calling the accessor on a shared production connection.","solutions":["Create the connection with ProxyDatabaseConnection::new(ProxyExecFn ...) wrapped into DatabaseConnection before calling this method","Gate the call behind a backend/type check so it only runs when a proxy connection is in use","Verify you are not confusing the proxy connection with MockDatabaseConnection in test setup"],"exampleFix":"// before\nlet conn = Database::connect(\"postgres://...\").await?;\nlet proxy = conn.as_proxy_connection(); // panics\n// after\nlet proxy_conn = ProxyDatabaseConnection::new(Box::new(my_exec_fn));\nlet conn: DatabaseConnection = proxy_conn.into();\nlet proxy = conn.as_proxy_connection(); // ok","handlingStrategy":"type-guard","validationCode":"// construct explicitly before use:\nlet proxy = ProxyDatabaseConnection::new(Box::new(exec_fn));\nlet conn: DatabaseConnection = proxy.into();","typeGuard":"fn is_proxy(conn: &DatabaseConnection) -> bool { std::panic::catch_unwind(|| conn.as_proxy_connection()).is_ok() }","tryCatchPattern":"let proxy = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conn.as_proxy_connection()));\nmatch proxy { Ok(p) => { /* use p */ }, Err(_) => eprintln!(\"connection is not a proxy connection\") }","preventionTips":["Keep proxy-backed connections in a distinct type/variable name in test harnesses","Do not call proxy accessors on connections built via Database::connect","Add a comment/fixture helper documenting which connections are proxy-backed"],"tags":["panic","proxy","testing","database"],"backgroundTag":"invalid-state-transition","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"}