Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python async for commit mechanism #67

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions icechunk-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,24 @@ impl PyIcechunkStore {
Ok(())
}

pub async fn commit(
&mut self,
pub fn commit<'py>(
&'py mut self,
py: Python<'py>,
update_branch_name: String,
message: String,
) -> PyIcechunkStoreResult<String> {
let (oid, _version) =
self.store.write().await.commit(&update_branch_name, &message).await?;
Ok(String::from(&oid))
) -> PyResult<Bound<'py, PyAny>> {
let store = Arc::clone(&self.store);

// The commit mechanism is async and calls tokio::spawn so we need to use the
// pyo3_asyncio_0_21::tokio helper to run the async function in the tokio runtime
pyo3_asyncio_0_21::tokio::future_into_py(py, async move {
let mut writeable_store = store.write().await;
let (oid, _version) = writeable_store
.commit(&update_branch_name, &message)
.await
.map_err(PyIcechunkStoreError::from)?;
Ok(String::from(&oid))
})
}

pub async fn empty(&self) -> PyIcechunkStoreResult<bool> {
Expand Down
Loading