diff --git a/betterproto-extras/src/merging.rs b/betterproto-extras/src/merging.rs index 683f5f0..5738bb1 100644 --- a/betterproto-extras/src/merging.rs +++ b/betterproto-extras/src/merging.rs @@ -3,7 +3,7 @@ use crate::{ py_any_extras::PyAnyExtras, }; use prost_reflect::{DynamicMessage, Value}; -use pyo3::{PyAny, PyObject, ToPyObject}; +use pyo3::{PyAny, PyObject, ToPyObject, types::PyBytes}; pub fn merge_msg_into_pyobj(obj: &PyAny, mut msg: DynamicMessage) -> Result<()> { for field in msg.take_fields() { @@ -22,7 +22,7 @@ pub fn merge_msg_into_pyobj(obj: &PyAny, mut msg: DynamicMessage) -> Result<()> if !buf.is_empty() { let mut unknown_fields = obj.getattr("_unknown_fields")?.extract::>()?; unknown_fields.append(&mut buf); - obj.setattr("_unknown_fields", unknown_fields)?; + obj.setattr("_unknown_fields", PyBytes::new(obj.py(), &unknown_fields))?; } obj.setattr("_serialized_on_wire", true)?;