{"record":{"id":"86aebb3bdd2ef2d1","repo":"SeaQL/sea-orm","slug":"not-postgres-connection","errorCode":null,"errorMessage":"Not Postgres Connection","messagePattern":"Not Postgres Connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/database/db_connection.rs","lineNumber":795,"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":777,"sourceCodeEnd":813,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/database/db_connection.rs#L777-L813","documentation":"get_postgres_connection_pool() returns the underlying sqlx::PgPool. It panics when the inner connection is not SqlxPostgresPoolConnection — i.e. the connection is MySQL, SQLite, mock, proxy, rusqlite, or Disconnected.","triggerScenarios":"Calling get_postgres_connection_pool() on a connection made from a non-postgres:// URL, on a MockDatabase or proxy connection, or on a Disconnected connection.","commonSituations":"DATABASE_URL env var pointing at MySQL/SQLite while code assumes Postgres; tests using MockDatabase then reaching for the pool; connect() failed earlier leaving a Disconnected handle.","solutions":["Connect with a postgres:// (or postgresql://) URL with the sqlx-postgres feature enabled","Guard with get_database_backend() == DbBackend::Postgres before unwrapping the pool","Confirm the earlier connect() call succeeded and the connection was not discarded"],"exampleFix":"// before\nlet conn = Database::connect(\"mysql://...\").await?;\nlet pool = conn.get_postgres_connection_pool(); // panics\n// after\nlet conn = Database::connect(\"postgres://...\").await?;\nlet pool = conn.get_postgres_connection_pool(); // ok","handlingStrategy":"validation","validationCode":"assert_eq!(conn.get_database_backend(), DbBackend::Postgres, \"raw pool access requires a Postgres connection\");\nlet pool = conn.get_postgres_connection_pool();","typeGuard":"fn as_pg_pool(conn: &DatabaseConnection) -> Option<&sqlx::PgPool> {\n    (conn.get_database_backend() == DbBackend::Postgres).then(|| conn.get_postgres_connection_pool())\n}","tryCatchPattern":"let pool = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conn.get_postgres_connection_pool()));\nif pool.is_err() { return Err(anyhow!(\"not a Postgres connection\")); }","preventionTips":["Check the DATABASE_URL scheme (postgres://) in config validation at startup","Do not call Postgres pool accessors in code shared with mock/proxy test connections","Centralize backend-specific pool access behind checked helpers"],"tags":["panic","postgres","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"}