{"record":{"id":"7f3085eba2c1760a","repo":"SeaQL/sea-orm","slug":"disconnected","errorCode":null,"errorMessage":"Disconnected","messagePattern":"Disconnected","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/database/db_connection.rs","lineNumber":678,"sourceCode":"    ///\n    /// # Panics\n    ///\n    /// Panics if [DatabaseConnection] is `Disconnected`.\n    pub fn get_database_backend(&self) -> DbBackend {\n        match &self.inner {\n            #[cfg(feature = \"sqlx-mysql\")]\n            DatabaseConnectionType::SqlxMySqlPoolConnection(_) => DbBackend::MySql,\n            #[cfg(feature = \"sqlx-postgres\")]\n            DatabaseConnectionType::SqlxPostgresPoolConnection(_) => DbBackend::Postgres,\n            #[cfg(feature = \"sqlx-sqlite\")]\n            DatabaseConnectionType::SqlxSqlitePoolConnection(_) => DbBackend::Sqlite,\n            #[cfg(feature = \"rusqlite\")]\n            DatabaseConnectionType::RusqliteSharedConnection(_) => DbBackend::Sqlite,\n            #[cfg(feature = \"mock\")]\n            DatabaseConnectionType::MockDatabaseConnection(conn) => conn.get_database_backend(),\n            #[cfg(feature = \"proxy\")]\n            DatabaseConnectionType::ProxyDatabaseConnection(conn) => conn.get_database_backend(),\n            DatabaseConnectionType::Disconnected => panic!(\"Disconnected\"),\n        }\n    }\n\n    /// Creates a [`SchemaBuilder`] for this backend\n    pub fn get_schema_builder(&self) -> SchemaBuilder {\n        Schema::new(self.get_database_backend()).builder()\n    }\n\n    #[cfg(feature = \"entity-registry\")]\n    #[cfg_attr(docsrs, doc(cfg(feature = \"entity-registry\")))]\n    /// Builds a schema for all the entites in the given module\n    pub fn get_schema_registry(&self, prefix: &str) -> SchemaBuilder {\n        let schema = Schema::new(self.get_database_backend());\n        crate::EntityRegistry::build_schema(schema, prefix)\n    }\n\n    /// Sets a callback to metric this connection\n    pub fn set_metric_callback<F>(&mut self, _callback: F)","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/database/db_connection.rs#L660-L696","documentation":"get_database_backend() reports which backend (Postgres, MySQL, Sqlite, ...) a connection uses. When the DatabaseConnection is in the Disconnected state (never connected, or the connection was closed/taken), there is no backend to report, so the library panics with \"Disconnected\".","triggerScenarios":"Calling get_database_backend() (directly or via get_schema_builder, query builders that inspect the backend) on a DatabaseConnection that was never initialized via connect(), or after it was replaced/torn down.","commonSituations":"Connect() returning Err but the code continuing to use the (disconnected) connection value; using a connection moved out of a struct; errors swallowed with let _ = connect();","solutions":["Ensure connect() succeeded (propagate the Result) before using the connection","Check conn.get_database_backend() only inside code paths reached after a successful connect","Store the backend explicitly at connect time if you need it before queries"],"exampleFix":"// before\nlet conn = Database::connect(&url).await; // Err swallowed\nlet backend = conn.get_database_backend(); // panics if connect failed\n// after\nlet conn = Database::connect(&url).await?;\nlet backend = conn.get_database_backend(); // safe","handlingStrategy":"try-catch","validationCode":"// propagate connect errors instead of ignoring them:\nlet conn = Database::connect(&url).await.map_err(|e| anyhow!(\"db connect failed: {e}\"))?;","typeGuard":"fn connected(conn: &DatabaseConnection) -> bool { std::panic::catch_unwind(|| { let _ = conn.get_database_backend(); }).is_ok() }","tryCatchPattern":"// at a boundary, catch panics from downstream library code:\nlet r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conn.get_database_backend()));\nif r.is_err() { /* re-initialize the connection */ }","preventionTips":["Never use `let _ =` or `.ok()` on Database::connect results","Initialize the connection once at startup and store it behind Arc in app state","Re-create the connection instead of reusing a handle after teardown"],"tags":["panic","connection","disconnected","database"],"backgroundTag":"connection-refused","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"}