{"record":{"id":"ac8fe19fb21aceb8","repo":"SeaQL/sea-orm","slug":"not-postgres-connection-ac8fe1","errorCode":null,"errorMessage":"Not Postgres Connection","messagePattern":"Not Postgres Connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/database/db_connection.rs","lineNumber":844,"sourceCode":"    /// 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    ///\n    /// # Panics\n    ///\n    /// Panics if [DbConn] is not a SQLite connection.\n    #[cfg(feature = \"sqlx-sqlite\")]\n    pub fn get_sqlite_connection_pool(&self) -> &sqlx::SqlitePool {\n        match &self.inner {\n            DatabaseConnectionType::SqlxSqlitePoolConnection(conn) => &conn.pool,\n            _ => panic!(\"Not SQLite Connection\"),\n        }\n    }\n}\n\nimpl DbBackend {","sourceCodeStart":826,"sourceCodeEnd":862,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/database/db_connection.rs#L826-L862","documentation":"`get_postgres_connection_pool()` unwraps the inner `SqlxPostgresPoolConnection` to return the raw `sqlx::PgPool`; all other `DatabaseConnectionType` variants fall into the `_ =>` arm and panic. It is only valid on a live PostgreSQL connection. `support_returning` on the Postgres pool path is where callers have hit it when the handle is not actually Postgres.","triggerScenarios":"Calling `db.get_postgres_connection_pool()` (directly or via Postgres-only paths like RETURNING support checks) on a MySQL/SQLite/mock/disconnected connection.","commonSituations":"Backend-agnostic code that calls Postgres-specific APIs; CI environment variables pointing at MySQL while the code assumes Postgres; swapping the database URL for a local SQLite dev DB.","solutions":["Guard with `if db.get_database_backend() == DbBackend::Postgres` before extracting the pool.","Correct the `DATABASE_URL`/config so the app actually connects to PostgreSQL.","Move Postgres-specific logic (e.g. RETURNING clauses) behind a backend check instead of assuming the pool type.","Keep mock/disconnected handles away from backend-specific extraction methods."],"exampleFix":"// before\nlet pool = db.get_postgres_connection_pool(); // panics on non-PG backends\n\n// after\nif db.get_database_backend() == DbBackend::Postgres {\n    let pool = db.get_postgres_connection_pool();\n} else {\n    return Err(anyhow!(\"Postgres connection required\"));\n}","handlingStrategy":"type-guard","validationCode":"if conn.get_database_backend() != DbBackend::Postgres {\n    return Err(anyhow!(\"get_postgres_connection_pool requires a Postgres backend\"));\n}","typeGuard":"fn as_pg_pool(conn: &DatabaseConnection) -> Option<&sqlx::PgPool> {\n    (conn.get_database_backend() == DbBackend::Postgres)\n        .then(|| conn.get_postgres_connection_pool())\n}","tryCatchPattern":"std::panic::catch_unwind(|| conn.get_postgres_connection_pool()) // last resort; prefer backend check","preventionTips":["Gate Postgres-only logic (RETURNING, pool access) behind a backend check.","Assert the CI DATABASE_URL points at Postgres when tests need PgPool.","Never mix mock/disconnected handles with pool extractors.","Centralize pool extraction in one guarded helper."],"tags":["panic","postgres","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"}