{"record":{"id":"d4cc80728fa06ef3","repo":"nautechsystems/nautilus_trader","slug":"failed-to-convert-instrument-to-python-e","errorCode":null,"errorMessage":"Failed to convert instrument to Python: {e}","messagePattern":"Failed to convert instrument to Python: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/providers/instruments.rs","lineNumber":1794,"sourceCode":"\n        #[cfg(feature = \"python\")]\n        {\n            use nautilus_model::python::instruments::instrument_any_to_pyobject;\n            use pyo3::{prelude::*, types::PyModule};\n\n            Python::attach(|py| {\n                let (module_name, callable_name) =\n                    filter_callable.rsplit_once('.').ok_or_else(|| {\n                        anyhow::anyhow!(\n                            \"Invalid filter_callable path {filter_callable:?}; expected module.callable\"\n                        )\n                    })?;\n                let callable = PyModule::import(py, module_name)\n                    .map_err(|e| anyhow::anyhow!(\"Failed to import {module_name}: {e}\"))?\n                    .getattr(callable_name)\n                    .map_err(|e| anyhow::anyhow!(\"Failed to resolve {filter_callable}: {e}\"))?;\n                let py_instrument = instrument_any_to_pyobject(py, instrument.clone())\n                    .map_err(|e| anyhow::anyhow!(\"Failed to convert instrument to Python: {e}\"))?;\n                callable\n                    .call1((py_instrument,))\n                    .and_then(|result| result.extract::<bool>())\n                    .map_err(|e| anyhow::anyhow!(\"filter_callable {filter_callable} failed: {e}\"))\n            })\n        }\n\n        #[cfg(not(feature = \"python\"))]\n        {\n            let _ = instrument;\n            anyhow::bail!(\n                \"filter_callable {filter_callable:?} requires the Interactive Brokers adapter to be built with the python feature\"\n            );\n        }\n    }\n\n    /// Batch load multiple instrument IDs.\n    ///","sourceCodeStart":1776,"sourceCodeEnd":1812,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/providers/instruments.rs#L1776-L1812","documentation":"The filter callable was resolved, but converting the Rust Instrument into a Python object via instrument_any_to_pyobject failed. This conversion can fail for instrument types that have no registered Python wrapper (pyo3 conversion error wrapped in the message).","triggerScenarios":"process_contract_detail applies filter_callable to an instrument whose concrete type lacks a Python conversion (unsupported instrument type in the model's Python bindings), or the instrument payload is corrupted/invalid.","commonSituations":"Filtering contracts for an exotic/experimental instrument type not covered by instrument_any_to_pyobject; using a filter with an instrument type the Python bindings don't support in the installed nautilus version.","solutions":["Update nautilus to a version whose Python bindings support the instrument type","Remove or narrow the filter_callable so it is not applied to the failing instrument type","Check the wrapped {e} to identify which instrument type failed conversion","Raise an issue / add a conversion arm for the missing type if on a recent version"],"exampleFix":"// before\n.filter_callable = \"mypkg.filters.keep_all\"  // applied to unsupported type\n// after\n// guard inside the filter pipeline: only apply filter to supported types, or drop the filter for that type","handlingStrategy":"fallback","validationCode":"// Only apply Python filters to instrument types with Python bindings:\nlet supported = matches!(instrument, Instrument::Any(_) ); // verify type coverage in nautilus python bindings","typeGuard":null,"tryCatchPattern":"match passes_filter_callable(instrument, callable) {\n    Ok(pass) => pass,\n    Err(e) if e.to_string().contains(\"convert instrument\") => {\n        log::warn!(\"filter skipped, conversion failed: {e}\");\n        true // or a safe default per your domain\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check that instrument_any_to_pyobject supports your instrument types in your nautilus version","Upgrade nautilus when using newer/less common instrument types with Python filters","Keep filters applied only to standard instrument kinds (FX, equity, futures, options)"],"tags":["rust","python","pyo3","instrument","conversion"],"backgroundTag":"type-mismatch","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}