Browse Source

replacing to_object

tags/v0.3.11-rc1
Shar-jeel-Sajid 10 months ago
parent
commit
852417a270
2 changed files with 43 additions and 7 deletions
  1. +42
    -6
      apis/python/operator/src/lib.rs
  2. +1
    -1
      binaries/runtime/src/operator/python.rs

+ 42
- 6
apis/python/operator/src/lib.rs View File

@@ -81,15 +81,41 @@ impl PyEvent {
pub fn to_py_dict(self, py: Python<'_>) -> PyResult<Py<PyDict>> {
let mut pydict = HashMap::new();
match &self.event {
MergedEvent::Dora(_) => pydict.insert("kind", "dora".to_object(py)),
MergedEvent::External(_) => pydict.insert("kind", "external".to_object(py)),
MergedEvent::Dora(_) => pydict.insert(
"kind",
"dora"
.into_pyobject(py)
.context("Failed to create pystring")?
.unbind()
.into(),
),
MergedEvent::External(_) => pydict.insert(
"kind",
"external"
.into_pyobject(py)
.context("Failed to create pystring")?
.unbind()
.into(),
),
};
match &self.event {
MergedEvent::Dora(event) => {
if let Some(id) = Self::id(event) {
pydict.insert("id", id.into_py(py));
pydict.insert(
"id",
id.into_pyobject(py)
.context("Failed to create id pyobject")?
.into(),
);
}
pydict.insert("type", Self::ty(event).to_object(py));
pydict.insert(
"type",
Self::ty(event)
.into_pyobject(py)
.context("Failed to create event pyobject")?
.unbind()
.into(),
);

if let Some(value) = self.value(py)? {
pydict.insert("value", value);
@@ -98,7 +124,14 @@ impl PyEvent {
pydict.insert("metadata", metadata);
}
if let Some(error) = Self::error(event) {
pydict.insert("error", error.to_object(py));
pydict.insert(
"error",
error
.into_pyobject(py)
.context("Failed to create error pyobject")?
.unbind()
.into(),
);
}
}
MergedEvent::External(event) => {
@@ -151,7 +184,10 @@ impl PyEvent {
Event::Input { metadata, .. } => Ok(Some(
metadata_to_pydict(metadata, py)
.context("Issue deserializing metadata")?
.to_object(py),
.into_pyobject(py)
.context("Failed to create metadata_to_pydice")?
.unbind()
.into(),
)),
_ => Ok(None),
}


+ 1
- 1
binaries/runtime/src/operator/python.rs View File

@@ -24,7 +24,7 @@ use tokio::sync::{mpsc::Sender, oneshot};
use tracing::{error, field, span, warn};

fn traceback(err: pyo3::PyErr) -> eyre::Report {
let traceback = Python::with_gil(|py| err.traceback_bound(py).and_then(|t| t.format().ok()));
let traceback = Python::with_gil(|py| err.traceback(py).and_then(|t| t.format().ok()));
if let Some(traceback) = traceback {
eyre::eyre!("{traceback}\n{err}")
} else {


Loading…
Cancel
Save