{"record":{"id":"2897bc99cf944126","repo":"SeaQL/sea-orm","slug":"not-mysql-connection","errorCode":null,"errorMessage":"Not MySQL Connection","messagePattern":"Not MySQL Connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/database/db_connection.rs","lineNumber":782,"sourceCode":"                // Nothing to cleanup, we just consume the `DatabaseConnection`\n                Ok(())\n            }\n            DatabaseConnectionType::Disconnected => Err(conn_err(\"Disconnected\")),\n        }\n    }\n}\n\nimpl DatabaseConnection {\n    /// Get [sqlx::MySqlPool]\n    ///\n    /// # Panics\n    ///\n    /// Panics if [DbConn] is not a MySQL connection.\n    #[cfg(feature = \"sqlx-mysql\")]\n    pub fn get_mysql_connection_pool(&self) -> &sqlx::MySqlPool {\n        match &self.inner {\n            DatabaseConnectionType::SqlxMySqlPoolConnection(conn) => &conn.pool,\n            _ => panic!(\"Not MySQL Connection\"),\n        }\n    }\n\n    /// Get [sqlx::PgPool]\n    ///\n    /// # Panics\n    ///\n    /// Panics if [DbConn] is not a Postgres connection.\n    #[cfg(feature = \"sqlx-postgres\")]\n    pub fn get_postgres_connection_pool(&self) -> &sqlx::PgPool {\n        match &self.inner {\n            DatabaseConnectionType::SqlxPostgresPoolConnection(conn) => &conn.pool,\n            _ => panic!(\"Not Postgres Connection\"),\n        }\n    }\n\n    /// Get [sqlx::SqlitePool]\n    ///","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/database/db_connection.rs#L764-L800","documentation":"get_mysql_connection_pool() hands out the underlying sqlx::MySqlPool so users can run raw sqlx. It panics when the DatabaseConnection wraps anything other than SqlxMySqlPoolConnection (Postgres, SQLite, mock, proxy, rusqlite, or Disconnected).","triggerScenarios":"Calling get_mysql_connection_pool() on a connection created for another backend (e.g. postgres:// or sqlite:// URL), on a MockDatabase connection, or on a Disconnected connection.","commonSituations":"Backend selected from an environment/config URL that is not MySQL while code assumes MySQL; test code using MockDatabase then trying to fetch the raw pool; feature sqlx-mysql not enabled so MySQL was never connectable.","solutions":["Connect with a mysql:// URL (with the sqlx-mysql feature enabled) before requesting the pool","Match on get_database_backend() == DbBackend::MySql before unwrapping the pool","Route raw-pool access behind a helper that takes a backend-specific connection type"],"exampleFix":"// before\nlet conn = Database::connect(\"postgres://...\").await?;\nlet pool = conn.get_mysql_connection_pool(); // panics\n// after\nlet conn = Database::connect(\"mysql://...\").await?;\nif conn.get_database_backend() == DbBackend::MySql {\n    let pool = conn.get_mysql_connection_pool();\n}","handlingStrategy":"validation","validationCode":"assert_eq!(conn.get_database_backend(), DbBackend::MySql, \"raw pool access requires a MySQL connection\");\nlet pool = conn.get_mysql_connection_pool();","typeGuard":"fn as_mysql_pool(conn: &DatabaseConnection) -> Option<&sqlx::MySqlPool> {\n    (conn.get_database_backend() == DbBackend::MySql).then(|| conn.get_mysql_connection_pool())\n}","tryCatchPattern":"let pool = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conn.get_mysql_connection_pool()));\nif pool.is_err() { return Err(anyhow!(\"not a MySQL connection\")); }","preventionTips":["Validate DATABASE_URL scheme (mysql://) at startup when using MySQL-specific APIs","Gate backend-specific code behind cfg(feature = \"sqlx-mysql\") and backend checks","Keep raw-pool escapes in one module that asserts the backend once"],"tags":["panic","mysql","sqlx","connection-pool"],"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"}