From 7757712ebc6eff93c0f6a1403e0823c2cae2ecbb Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Fri, 5 Jun 2026 14:32:01 -0500 Subject: [PATCH] Fix `db_pool` extraction --- rust/src/handlers/mod.rs | 2 +- rust/src/storage/db/python_db_pool.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/rust/src/handlers/mod.rs b/rust/src/handlers/mod.rs index 2c7d97c4eb..4e9272734b 100644 --- a/rust/src/handlers/mod.rs +++ b/rust/src/handlers/mod.rs @@ -22,6 +22,7 @@ use pyo3::{ use crate::config::SynapseConfig; use crate::storage::db::python_db_pool::PythonDatabasePool; use crate::storage::store::Store; +use crate::UnwrapInfallible; pub mod versions; @@ -42,7 +43,6 @@ impl RustHandlers { .call_method0("get_datastores")? .into_pyobject(py) .unwrap_infallible() - .unbind() .getattr("main")? .getattr("db_pool")? .extract()?; diff --git a/rust/src/storage/db/python_db_pool.rs b/rust/src/storage/db/python_db_pool.rs index b26445b305..44c4ddad01 100644 --- a/rust/src/storage/db/python_db_pool.rs +++ b/rust/src/storage/db/python_db_pool.rs @@ -37,7 +37,18 @@ impl DatabaseEngine { /// Wrapper for a `DatabasePool` from the Python side of Synapse. pub struct PythonDatabasePool { /// The underlying `DatabasePool` - database_pool_py: Bound<'py, PyAny>, + database_pool_py: Py, +} + +impl<'a, 'py> FromPyObject<'a, 'py> for PythonDatabasePool { + type Error = PyErr; + + /// Extract from a Python `DatabasePool` passed as an argument. + fn extract(database_pool_py: Borrowed<'a, 'py, PyAny>) -> PyResult { + Ok(Self { + database_pool_py: database_pool_py.to_owned().unbind(), + }) + } } #[async_trait::async_trait] @@ -151,8 +162,6 @@ impl<'a, 'py> FromPyObject<'a, 'py> for LoggingTransactionWrapper { type Error = PyErr; /// Extract from a Python `LoggingTransaction` passed as an argument. - /// - /// The resulting wrapper has `done_tx = None`; Python owns the transaction lifetime. fn extract(logging_transaction_py: Borrowed<'a, 'py, PyAny>) -> PyResult { let database_engine = detect_engine(&logging_transaction_py.to_owned())?; Ok(Self {