Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
fix(python): propagate conversion attribute errors (#1291)
Rainaxyzd8d2efa46703
diff --git a/crates/switchyard-py/src/py_serde.rs b/crates/switchyard-py/src/py_serde.rsindex 8a79e16bd..5d27ba150 100644--- a/crates/switchyard-py/src/py_serde.rs+++ b/crates/switchyard-py/src/py_serde.rs@@ -24,7 +24,7 @@ pub(crate) fn to_python<T: Serialize>(py: Python<'_>, value: &T) -> PyResult<Py<}fn jsonable_python(value: &Bound<'_, PyAny>) -> PyResult<Py<PyAny>> {- if let Ok(model_dump) = value.getattr("model_dump")+ if let Some(model_dump) = value.getattr_opt("model_dump")?&& model_dump.is_callable(){let kwargs = PyDict::new(value.py());@@ -32,7 +32,7 @@ fn jsonable_python(value: &Bound<'_, PyAny>) -> PyResult<Py<PyAny>> {kwargs.set_item("exclude_none", true)?;return model_dump.call((), Some(&kwargs)).map(Bound::unbind);}- if let Ok(to_dict) = value.getattr("to_dict")+ if let Some(to_dict) = value.getattr_opt("to_dict")?&& to_dict.is_callable(){return to_dict.call0().map(Bound::unbind);diff --git a/tests/test_libsy_minimal_bindings.py b/tests/test_libsy_minimal_bindings.pyindex 4bc0c5b10..2336bc432 100644--- a/tests/test_libsy_minimal_bindings.py+++ b/tests/test_libsy_minimal_bindings.py@@ -409,6 +409,20 @@ async def test_noop_needs_no_client() -> None:assert response["outputs"][0]["content"] == [{"type": "text", "text": "OK"}][email protected](("method", "base"), [("model_dump", object), ("to_dict", dict)])+def test_conversion_getter_error_propagates(method: str, base: type) -> None:+ error = RuntimeError("conversion getter failed")++ def fail(self: Any) -> Any:+ raise error++ request_type = type("Request", (base,), {method: property(fail)})+ request = request_type(request_body()) if base is dict else request_type()+ with pytest.raises(RuntimeError) as caught:+ algorithms.noop().run_stream(request, {"any": ["fixture"]})+ assert caught.value is error++@pytest.mark.parametrize(("headers", "message"),[