{"record":{"id":"58fa33b76a79ebe3","repo":"SeaQL/sea-orm","slug":"not-mysql-connection-58fa33","errorCode":null,"errorMessage":"Not MySQL Connection","messagePattern":"Not MySQL Connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/database/db_connection.rs","lineNumber":831,"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":813,"sourceCodeEnd":849,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/database/db_connection.rs#L813-L849","documentation":"`get_mysql_connection_pool()` extracts the raw `sqlx::MySqlPool` from a SeaORM connection, but only when the inner variant is `SqlxMySqlPoolConnection`. Any other backend (Postgres, SQLite, mock, disconnected) hits the catch-all arm and panics. The docs explicitly state it panics if the connection is not MySQL.","triggerScenarios":"Calling `db.get_mysql_connection_pool()` on a connection established from a `postgres://`, `sqlite://` URI, a `MockDatabase`, or a disconnected handle.","commonSituations":"Code shared across backends that unconditionally pulls the MySQL pool; config/env pointing at the wrong database URL; running integration tests against the mock backend; compile-time feature mismatch (`sqlx-mysql` enabled but app connects to Postgres).","solutions":["Verify the connection backend first: only call `get_mysql_connection_pool()` when `db.get_database_backend() == DbBackend::MySql`.","Check the database URI in configuration points to MySQL (`mysql://`), not another engine.","Use `match` on the connection or a `try_get_*` style accessor instead of the panicking getter in generic code.","In tests, configure the mock database only where the mysql-specific path is not exercised."],"exampleFix":"// before\nlet pool = db.get_mysql_connection_pool(); // panics if backend isn't MySQL\n\n// after\nassert!(matches!(db.get_database_backend(), DbBackend::MySql), \"expected MySQL connection\");\nlet pool = db.get_mysql_connection_pool();","handlingStrategy":"type-guard","validationCode":"if conn.get_database_backend() != DbBackend::MySql {\n    return Err(anyhow!(\"get_mysql_connection_pool requires a MySQL backend\"));\n}","typeGuard":"fn as_mysql_pool(conn: &DatabaseConnection) -> Option<&sqlx::MySqlPool> {\n    (conn.get_database_backend() == DbBackend::MySql)\n        .then(|| conn.get_mysql_connection_pool())\n}","tryCatchPattern":"std::panic::catch_unwind(|| conn.get_mysql_connection_pool()) // last resort; prefer backend check","preventionTips":["Check DbBackend before any engine-specific pool accessor.","Validate DATABASE_URL scheme matches the expected engine at startup.","Keep backend-specific code behind feature flags or enum dispatch.","Add debug_assert on backend in dev/test paths."],"tags":["panic","mysql","wrong-backend","sqlx"],"backgroundTag":"incompatible-source-type","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"}