SeaQL/sea-orm · critical
Not proxy connection
Error message
Not proxy connection
What it means
`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.
Source
Thrown at src/database/db_connection.rs:610
.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 async fn load_rbac(&self) -> Result<(), DbErr> {
self.load_rbac_from(self).await
}
/// Load RBAC data from the given database connection and setup RBAC engine.
/// This could be from another database.
pub async fn load_rbac_from(&self, db: &DbConn) -> Result<(), DbErr> {
let engine = crate::rbac::RbacEngine::load_from(db).await?;
self.rbac.replace(engine);
Ok(())View on GitHub (pinned to e29bcd1b41)
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.
Example fix
// before
let db = Database::connect("mysql://localhost/app").await?;
let proxy = db.as_proxy_connection(); // panics: not a proxy connection
// after
let db = ProxyDatabaseConnector::wrap(MyAppProxy::default());
let proxy = db.as_proxy_connection(); // ok Defensive patterns
Strategy: type-guard
Validate before calling
// Only build the handle through the proxy connector let db = ProxyDatabaseConnector::wrap(MyProxy::default()); let _proxy = db.as_proxy_connection(); // safe by construction
Type guard
struct ProxyDb { conn: DatabaseConnection } // conn is ALWAYS ProxyDatabaseConnector::wrap(...)
impl ProxyDb {
fn wrap(p: impl Proxy) -> Self { Self { conn: ProxyDatabaseConnector::wrap(p) } }
fn proxy(&self) -> &ProxyDatabaseConnection { self.conn.as_proxy_connection() }
} Try / catch
// panic! is not catchable in Rust; enforce at construction time
fn ensure_proxy(db: &DatabaseConnection) -> Option<&ProxyDatabaseConnection> {
// only call as_proxy_connection in paths that built the conn via ProxyDatabaseConnector
None
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Not mock connection
- Failed to set value for {:?}: {e:?}
- cannot apply alias for AsEnum with asterisk
- cannot apply alias for AsEnum with expr other than Column
- cannot apply alias for expr other than Column or AsEnum
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/1fcdf790ad043a83.
Report an issue: GitHub.