{"record":{"id":"49f493b8719cf74b","repo":"nautechsystems/nautilus_trader","slug":"python-on-reset-failed-e-49f493","errorCode":null,"errorMessage":"Python on_reset failed: {e}","messagePattern":"Python on_reset failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/python/algorithm.rs","lineNumber":565,"sourceCode":"            .map_err(|e| anyhow::anyhow!(\"Python on_start failed: {e}\"))\n    }\n\n    fn on_stop(&mut self) -> anyhow::Result<()> {\n        ExecutionAlgorithm::on_stop(self)?;\n        self.dispatch_no_args(\"on_stop\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_stop failed: {e}\"))\n    }\n\n    fn on_resume(&mut self) -> anyhow::Result<()> {\n        ExecutionAlgorithm::on_resume(self)?;\n        self.dispatch_no_args(\"on_resume\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_resume failed: {e}\"))\n    }\n\n    fn on_reset(&mut self) -> anyhow::Result<()> {\n        ExecutionAlgorithm::on_reset(self)?;\n        self.dispatch_no_args(\"on_reset\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_reset failed: {e}\"))\n    }\n\n    fn on_dispose(&mut self) -> anyhow::Result<()> {\n        self.dispatch_no_args(\"on_dispose\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_dispose failed: {e}\"))\n    }\n\n    fn on_degrade(&mut self) -> anyhow::Result<()> {\n        self.dispatch_no_args(\"on_degrade\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_degrade failed: {e}\"))\n    }\n\n    fn on_fault(&mut self) -> anyhow::Result<()> {\n        self.dispatch_no_args(\"on_fault\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_fault failed: {e}\"))\n    }\n\n    fn on_time_event(&mut self, event: &TimeEvent) -> anyhow::Result<()> {","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/python/algorithm.rs#L547-L583","documentation":"The DataActor on_reset path runs Rust ExecutionAlgorithm::on_reset then dispatches the Python `on_reset` callback; Python exceptions are re-wrapped with this message. Reset should return the component to a clean state, so a failure here means user Python code could not clear or rebuild its state.","triggerScenarios":"Calling on_reset when the Python on_reset raises — e.g. clearing structures that are None, deleting attributes that don't exist, or an invalid no-arg dispatch.","commonSituations":"Backtesting loops that reset between runs hitting a KeyError/AttributeError in the user's reset; double-reset when reset is invoked after dispose; partially initialized object being reset.","solutions":["Read the chained `{e}` traceback and fix the Python on_reset implementation.","Make on_reset defensive: use getattr/setdefault patterns so missing attributes don't raise.","Ensure on_reset is only called on a live, initialized instance (check lifecycle order).","Verify the zero-arg `def on_reset(self)` signature."],"exampleFix":"// before\ndef on_reset(self):\n    del self.orders  # AttributeError if never set\n\n// after\ndef on_reset(self):\n    self.orders = {}","handlingStrategy":"try-catch","validationCode":"# Python: reset defensively\nfor attr in (\"orders\", \"cache\", \"handlers\"):\n    if hasattr(self, attr): delattr(self, attr)","typeGuard":null,"tryCatchPattern":"if let Err(e) = actor.on_reset() {\n    log::error!(\"python on_reset failed: {e:#}\"); // recreate the component if reset cannot clean state\n}","preventionTips":["Initialize all mutable attributes in __init__ so on_reset never touches missing fields.","Prefer assigning fresh containers over delattr in on_reset.","Run backtests that reset repeatedly to catch non-idempotent reset logic."],"tags":["rust","python","pyo3","lifecycle","on-reset"],"backgroundTag":"api-error-response","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"}