{"record":{"id":"77567008f40f4184","repo":"nautechsystems/nautilus_trader","slug":"failed-to-convert-historical-data-to-python-unsup","errorCode":null,"errorMessage":"Failed to convert historical data to Python: unsupported type","messagePattern":"Failed to convert historical data to Python: unsupported type","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1209,"sourceCode":"    fn on_pool_fee_collect(&mut self, collect: &PoolFeeCollect) -> anyhow::Result<()> {\n        self.dispatch_on_pool_fee_collect(collect.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_pool_fee_collect failed: {e}\"))\n    }\n\n    #[cfg(feature = \"defi\")]\n    fn on_pool_flash(&mut self, flash: &PoolFlash) -> anyhow::Result<()> {\n        self.dispatch_on_pool_flash(flash.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_pool_flash failed: {e}\"))\n    }\n\n    fn on_historical_data(&mut self, data: &dyn Any) -> anyhow::Result<()> {\n        Python::attach(|py| {\n            let py_data: Py<PyAny> = if let Some(custom_data) = data.downcast_ref::<CustomData>() {\n                Py::new(py, custom_data.clone())?.into_any()\n            } else if let Some(custom_data) = data.downcast_ref::<Vec<CustomData>>() {\n                custom_data.clone().into_py_any(py)?\n            } else {\n                anyhow::bail!(\"Failed to convert historical data to Python: unsupported type\");\n            };\n            self.dispatch_on_historical_data(py_data)\n                .map_err(|e| anyhow::anyhow!(\"Python on_historical_data failed: {e}\"))\n        })\n    }\n\n    fn on_historical_book_deltas(&mut self, deltas: &[OrderBookDelta]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_book_deltas(deltas.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_book_deltas failed: {e}\"))\n    }\n\n    fn on_historical_book_depth(&mut self, depths: &[OrderBookDepth10]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_book_depth(depths.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_book_depth failed: {e}\"))\n    }\n\n    fn on_historical_quotes(&mut self, quotes: &[QuoteTick]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_quotes(quotes.to_vec())","sourceCodeStart":1191,"sourceCodeEnd":1227,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1191-L1227","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nactor.call_on_historical_data(deltas); // OrderBookDeltas: unsupported\n// after\nlet custom = CustomData::new(deltas);\nactor.call_on_historical_data(custom);","handlingStrategy":"type-guard","validationCode":"# only send supported types through the historical-data bridge\nif not isinstance(data, (CustomData, list)) or (isinstance(data, list) and data and not isinstance(data[0], CustomData)):\n    raise TypeError(\"historical data must be CustomData or Vec<CustomData>\")","typeGuard":"def is_custom_data_payload(data) -> bool:\n    return isinstance(data, CustomData) or (isinstance(data, list) and all(isinstance(x, CustomData) for x in data))","tryCatchPattern":"try:\n    actor.on_historical_data(data)\nexcept Exception as e:\n    if \"unsupported type\" in str(e):\n        wrap_and_retry_as_custom_data(data)","preventionTips":["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."],"tags":["python","conversion","historical-data","custom-data"],"backgroundTag":"unsupported-operation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}