{"record":{"id":"337fd7b37d51ac8c","repo":"nautechsystems/nautilus_trader","slug":"python-simulationmodule-reset-failed-e","errorCode":null,"errorMessage":"Python SimulationModule.reset failed: {e}","messagePattern":"Python SimulationModule\\.reset failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/python/modules.rs","lineNumber":324,"sourceCode":"            Ok(())\n        })\n        .map_err(|e| anyhow::anyhow!(\"Python SimulationModule.acknowledge failed: {e}\"))\n    }\n\n    fn log_diagnostics(&self) -> anyhow::Result<()> {\n        Python::attach(|py| -> anyhow::Result<()> {\n            self.obj.bind(py).call_method0(\"log_diagnostics\")?;\n            Ok(())\n        })\n        .map_err(|e| anyhow::anyhow!(\"Python SimulationModule.log_diagnostics failed: {e}\"))\n    }\n\n    fn reset(&self) -> anyhow::Result<()> {\n        Python::attach(|py| -> anyhow::Result<()> {\n            self.obj.bind(py).call_method0(\"reset\")?;\n            Ok(())\n        })\n        .map_err(|e| anyhow::anyhow!(\"Python SimulationModule.reset failed: {e}\"))\n    }\n}\n\nfn pyobject_to_builtin_simulation_module_any(\n    obj: &Bound<'_, PyAny>,\n) -> Option<SimulationModuleAny> {\n    if let Ok(module) = obj.extract::<PyRef<'_, CfdSwapModule>>() {\n        return Some(SimulationModuleAny::CfdSwap((*module).clone()));\n    }\n\n    if let Ok(module) = obj.extract::<PyRef<'_, FXRolloverInterestModule>>() {\n        return Some(SimulationModuleAny::FXRolloverInterest((*module).clone()));\n    }\n    None\n}\n\n/// Extracts a Python object into a declarative simulation module.\n///","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/python/modules.rs#L306-L342","documentation":"Calling the Python SimulationModule object's reset method raised a Python exception; the Rust wrapper propagates it as an anyhow error, so resetting the custom simulation module fails with the underlying Python error message.","triggerScenarios":"Calling node.reset() / engine reset where the Python module's reset() raises, typically because reset assumes state that was never initialized (accessing attributes before first process call).","commonSituations":"Running multiple iterations of a backtest where a module's reset references objects created lazily in process(); deleting keys that don't exist.","solutions":["Fix the exception in the Python module's reset per the traceback.","Make reset defensive: use del self.x if hasattr(self, 'x') or initialize defaults in __init__ and restore them in reset.","Ensure __init__ creates every attribute that reset touches."],"exampleFix":"# before\ndef reset(self):\n    self.book.clear()\n    self.book = None  # was never set before first run\n# after\ndef __init__(self):\n    self.book = {}\ndef reset(self):\n    self.book = {}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"def reset(self):\n    try:\n        self.book = {}\n        self.counts = {}\n    except Exception:\n        logging.exception(\"reset failed\")\n        raise\n","preventionTips":["Initialize every attribute reset() touches in __init__, so reset works before first use.","Restore __init__-era defaults in reset rather than deleting attributes.","Run at least two backtest iterations to exercise the reset path."],"tags":["python","backtest","simulation-module","lifecycle"],"backgroundTag":"upstream-api-error","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"}