{"record":{"id":"fe488cc9a3e08f66","repo":"nautechsystems/nautilus_trader","slug":"failed-to-create-list-e","errorCode":null,"errorMessage":"Failed to create list: {e}","messagePattern":"Failed to create list: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/python/data/mod.rs","lineNumber":384,"sourceCode":"\n        let wrapper = PythonCustomDataWrapper::new(py, &instance)\n            .map_err(|e| anyhow::anyhow!(\"Failed to create wrapper: {e}\"))?;\n\n        Ok(Arc::new(wrapper) as Arc<dyn crate::data::CustomDataTrait>)\n    })\n}\n\n/// Encodes `CustomData` items to `RecordBatch` via Python `encode_record_batch_py`.\n#[allow(unsafe_code)]\n#[cfg(all(feature = \"python\", feature = \"arrow\"))]\nfn py_encode_custom_data_to_record_batch(\n    items: &[std::sync::Arc<dyn crate::data::CustomDataTrait>],\n) -> Result<arrow::record_batch::RecordBatch, anyhow::Error> {\n    pyo3::Python::attach(|py| {\n        let py_items: Result<Vec<_>, _> = items.iter().map(|item| item.to_pyobject(py)).collect();\n        let py_items = py_items.map_err(|e| anyhow::anyhow!(\"Failed to convert to Python: {e}\"))?;\n        let py_list = pyo3::types::PyList::new(py, &py_items)\n            .map_err(|e| anyhow::anyhow!(\"Failed to create list: {e}\"))?;\n\n        let first = items\n            .first()\n            .ok_or_else(|| anyhow::anyhow!(\"No items to encode\"))?;\n        let first_py = first.to_pyobject(py)?;\n\n        if first_py\n            .bind(py)\n            .hasattr(\"encode_record_batch_py\")\n            .unwrap_or(false)\n        {\n            let py_batch = first_py\n                .bind(py)\n                .call_method1(\"encode_record_batch_py\", (py_list,))\n                .map_err(|e| anyhow::anyhow!(\"Failed to call encode_record_batch_py: {e}\"))?;\n\n            let mut ffi_array = arrow::ffi::FFI_ArrowArray::empty();\n            let mut ffi_schema = arrow::ffi::FFI_ArrowSchema::empty();","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/python/data/mod.rs#L366-L402","documentation":"After converting custom data items to Python objects, the encoder builds a `PyList` of them to pass to the Python-side `encode_record_batch_py`. Pyo3's `PyList::new` returns an error if any element cannot be converted to a Python object or the list construction fails; that error is wrapped as \"Failed to create list\". This is a preparatory step before calling into Python, so the whole encode fails.","triggerScenarios":"Calling the Arrow encode path for custom data when `pyo3::types::PyList::new(py, &py_items)` fails — rare in practice since items were already converted, but possible if an element panics or conversion to a Python object fails during list materialization.","commonSituations":"Pyo3 version edge cases with `IntoPyObject`/`ToPyObject` conversions for wrapper types; embedding scenarios where the Python interpreter is in a bad state; items containing objects that fail conversion when collected into the list.","solutions":["Check the embedded `{e}` for the underlying pyo3 conversion error.","Confirm the items were valid Python objects (the preceding 'Failed to convert to Python' step succeeded).","Upgrade or align pyo3 versions between nautilus crates and any custom build code.","Retry the encode in a fresh interpreter/GIL context if running embedded."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    batch = encode_to_record_batch(items)\nexcept Exception as e:\n    logger.error(f\"PyList construction failed: {e}\")\n    raise","preventionTips":["Keep pyo3 versions aligned across nautilus crates and custom builds","Avoid embedding/unembedding interpreters mid-encode","Validate items convert to Python before batch encoding"],"tags":["python","pyo3","arrow","custom-data"],"backgroundTag":"json-serialization-failed","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"}