nautechsystems/nautilus_trader · error · anyhow::Error
Failed to convert historical data to Python: unsupported typ
Error message
Failed to convert historical data to Python: unsupported type
What it means
When an actor receives historical data, the Rust side converts it to a Python object before dispatching to on_historical_data. Only CustomData and Vec<CustomData> are supported for this conversion; any other data type bails. The library throws it because there is no Python representation path for the given historical data type.
Source
Thrown at crates/common/src/python/actor.rs:1209
fn on_pool_fee_collect(&mut self, collect: &PoolFeeCollect) -> anyhow::Result<()> {
self.dispatch_on_pool_fee_collect(collect.clone())
.map_err(|e| anyhow::anyhow!("Python on_pool_fee_collect failed: {e}"))
}
#[cfg(feature = "defi")]
fn on_pool_flash(&mut self, flash: &PoolFlash) -> anyhow::Result<()> {
self.dispatch_on_pool_flash(flash.clone())
.map_err(|e| anyhow::anyhow!("Python on_pool_flash failed: {e}"))
}
fn on_historical_data(&mut self, data: &dyn Any) -> anyhow::Result<()> {
Python::attach(|py| {
let py_data: Py<PyAny> = if let Some(custom_data) = data.downcast_ref::<CustomData>() {
Py::new(py, custom_data.clone())?.into_any()
} else if let Some(custom_data) = data.downcast_ref::<Vec<CustomData>>() {
custom_data.clone().into_py_any(py)?
} else {
anyhow::bail!("Failed to convert historical data to Python: unsupported type");
};
self.dispatch_on_historical_data(py_data)
.map_err(|e| anyhow::anyhow!("Python on_historical_data failed: {e}"))
})
}
fn on_historical_book_deltas(&mut self, deltas: &[OrderBookDelta]) -> anyhow::Result<()> {
self.dispatch_on_historical_book_deltas(deltas.to_vec())
.map_err(|e| anyhow::anyhow!("Python on_historical_book_deltas failed: {e}"))
}
fn on_historical_book_depth(&mut self, depths: &[OrderBookDepth10]) -> anyhow::Result<()> {
self.dispatch_on_historical_book_depth(depths.to_vec())
.map_err(|e| anyhow::anyhow!("Python on_historical_book_depth failed: {e}"))
}
fn on_historical_quotes(&mut self, quotes: &[QuoteTick]) -> anyhow::Result<()> {
self.dispatch_on_historical_quotes(quotes.to_vec())View on GitHub (pinned to 18893faf8b)
Solutions
- Wrap the historical data in CustomData (or a Vec<CustomData>) before dispatching to the actor.
- Route non-custom data types through the appropriate typed handler (e.g. on_data / on_order_book_deltas) instead of the historical CustomData bridge.
- Extend the conversion match if you own the code and need support for another concrete type.
Example fix
// before actor.call_on_historical_data(deltas); // OrderBookDeltas: unsupported // after let custom = CustomData::new(deltas); actor.call_on_historical_data(custom);
Defensive patterns
Strategy: type-guard
Validate before calling
# only send supported types through the historical-data bridge
if not isinstance(data, (CustomData, list)) or (isinstance(data, list) and data and not isinstance(data[0], CustomData)):
raise TypeError("historical data must be CustomData or Vec<CustomData>") Type guard
def is_custom_data_payload(data) -> bool:
return isinstance(data, CustomData) or (isinstance(data, list) and all(isinstance(x, CustomData) for x in data)) Try / catch
try:
actor.on_historical_data(data)
except Exception as e:
if "unsupported type" in str(e):
wrap_and_retry_as_custom_data(data) Prevention
- Always wrap non-custom historical payloads in CustomData before dispatch.
- Route built-in data types to their dedicated handlers rather than on_historical_data.
- Document the accepted types of the historical-data bridge for adapter authors.
When it happens
Trigger: Calling the historical-data dispatch path (requesting/replaying historical data into an actor) with data that downcasts to neither CustomData nor Vec<CustomData> — e.g. raw OrderBookDeltas, QuoteTick lists, or other core data passed through this CustomData-oriented bridge.
Common situations: Wrapping historical data requests that return core types rather than CustomData; adapters feeding non-custom backtest/replay data through the custom-data dispatch; migration of code that previously used the generic on_historical_data path with built-in types.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Python on_historical_data failed: {e}
- Failed to convert to Python: {e}
- Python object has no to_json() method or __dict__ attribute
- Instances must have encode_record_batch_py method
- Failed to convert historical data to Python: unsupported typ
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/77567008f40f4184.
Report an issue: GitHub.