diff --git a/apis/python/node/src/lib.rs b/apis/python/node/src/lib.rs index 72cb5f79..35b371c8 100644 --- a/apis/python/node/src/lib.rs +++ b/apis/python/node/src/lib.rs @@ -218,9 +218,9 @@ impl Node { value .to_pyarrow(py) .context("failed to convert value to pyarrow") - .unwrap_or_else(|err| PyErr::from(err).to_object(py)) + .unwrap_or_else(|err| err_to_pyany(err, py)) }), - Err(err) => Python::with_gil(|py| PyErr::from(err).to_object(py)), + Err(err) => Python::with_gil(|py| err_to_pyany(err, py)), } }); futures::pin_mut!(s); @@ -239,6 +239,14 @@ impl Node { } } +fn err_to_pyany(err: eyre::Report, gil: Python<'_>) -> Py { + PyErr::from(err) + .into_pyobject(gil) + .unwrap_or_else(|infallible| match infallible {}) + .into_any() + .unbind() +} + struct Events { inner: EventsInner, cleanup_handle: NodeCleanupHandle, diff --git a/apis/python/operator/src/lib.rs b/apis/python/operator/src/lib.rs index 16165cda..2e3031e3 100644 --- a/apis/python/operator/src/lib.rs +++ b/apis/python/operator/src/lib.rs @@ -140,7 +140,14 @@ impl PyEvent { } if let Some(cleanup) = self._cleanup.clone() { - pydict.insert("_cleanup", cleanup.into_py(py)); + pydict.insert( + "_cleanup", + cleanup + .into_pyobject(py) + .context("failed to convert cleanup handle to pyobject")? + .into_any() + .unbind(), + ); } Ok(pydict