SeaQL/sea-orm · error
Not proxy connection
Error message
Not proxy connection
What it means
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.
Source
Thrown at sea-orm-sync/src/database/db_connection.rs:564
.as_mock_connection()
.get_mocker_mutex()
.lock()
.expect("Fail to acquire mocker");
mocker.drain_transaction_log()
}
}
#[cfg(feature = "proxy")]
impl DatabaseConnection {
/// Generate a database connection for testing the Proxy database
///
/// # Panics
///
/// Panics if [DbConn] is not a proxy connection.
pub fn as_proxy_connection(&self) -> &crate::ProxyDatabaseConnection {
match &self.inner {
DatabaseConnectionType::ProxyDatabaseConnection(proxy_conn) => proxy_conn,
_ => panic!("Not proxy connection"),
}
}
}
#[cfg(feature = "rbac")]
impl DatabaseConnection {
/// Load RBAC data from the same database as this connection and setup RBAC engine.
/// If the RBAC engine already exists, it will be replaced.
pub fn load_rbac(&self) -> Result<(), DbErr> {
self.load_rbac_from(self)
}
/// Load RBAC data from the given database connection and setup RBAC engine.
/// This could be from another database.
pub fn load_rbac_from(&self, db: &DbConn) -> Result<(), DbErr> {
let engine = crate::rbac::RbacEngine::load_from(db)?;
self.rbac.replace(engine);
Ok(())View on GitHub (pinned to e29bcd1b41)
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
Example fix
// before
let conn = Database::connect("postgres://...").await?;
let proxy = conn.as_proxy_connection(); // panics
// after
let proxy_conn = ProxyDatabaseConnection::new(Box::new(my_exec_fn));
let conn: DatabaseConnection = proxy_conn.into();
let proxy = conn.as_proxy_connection(); // ok Defensive patterns
Strategy: type-guard
Validate before calling
// construct explicitly before use: let proxy = ProxyDatabaseConnection::new(Box::new(exec_fn)); let conn: DatabaseConnection = proxy.into();
Type guard
fn is_proxy(conn: &DatabaseConnection) -> bool { std::panic::catch_unwind(|| conn.as_proxy_connection()).is_ok() } Try / catch
let proxy = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conn.as_proxy_connection()));
match proxy { Ok(p) => { /* use p */ }, Err(_) => eprintln!("connection is not a proxy connection") } Prevention
- 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
When it happens
Trigger: Calling as_proxy_connection() on a connection not created via ProxyDatabaseConnection / DatabaseConnectionType::ProxyDatabaseConnection, e.g. a normal connect() result or a mock connection.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Not mock connection
- Disconnected
- There is no open transaction to commit
- There is no open transaction to rollback
- Not mock connection
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/76d0734569ffb25e.
Report an issue: GitHub.