{"record":{"id":"3f202315a79003db","repo":"nautechsystems/nautilus_trader","slug":"python-on-reset-failed-e","errorCode":null,"errorMessage":"Python on_reset failed: {e}","messagePattern":"Python on_reset failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1035,"sourceCode":"impl DataActor for PyDataActorInner {\n    fn on_start(&mut self) -> anyhow::Result<()> {\n        self.dispatch_on_start()\n            .map_err(|e| anyhow::anyhow!(\"Python on_start failed: {e}\"))\n    }\n\n    fn on_stop(&mut self) -> anyhow::Result<()> {\n        self.dispatch_on_stop()\n            .map_err(|e| anyhow::anyhow!(\"Python on_stop failed: {e}\"))\n    }\n\n    fn on_resume(&mut self) -> anyhow::Result<()> {\n        self.dispatch_on_resume()\n            .map_err(|e| anyhow::anyhow!(\"Python on_resume failed: {e}\"))\n    }\n\n    fn on_reset(&mut self) -> anyhow::Result<()> {\n        self.dispatch_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_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_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_on_fault()\n            .map_err(|e| anyhow::anyhow!(\"Python on_fault failed: {e}\"))\n    }\n\n    fn on_save(&self) -> anyhow::Result<IndexMap<String, Vec<u8>>> {","sourceCodeStart":1017,"sourceCodeEnd":1053,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1017-L1053","documentation":"Raised by the Rust `DataActor` bridge when the Python actor's `on_reset()` callback raises an exception. `dispatch_on_reset()` forwards to the Python method and any exception becomes this anyhow error. on_reset runs when returning a component to a fresh pre-start state.","triggerScenarios":"Any exception thrown in the user's Python `on_reset`: calling reset on an object that is None, clearing collections that don't exist, or invoking external APIs during reset that fail.","commonSituations":"Backtest/kitchen-sink runs resetting strategies between iterations where reset code assumes live-only resources; AttributeError from resetting attributes that were only created conditionally in on_start.","solutions":["Read the Python traceback inside the error to find the failing statement in on_reset.","Use getattr/hasattr guards or initialize all resettable attributes in __init__ so reset never touches missing state.","Avoid external I/O in on_reset; keep it to clearing in-memory state.","Reproduce with a direct call: instantiate the actor, run on_start then on_reset under a test."],"exampleFix":"// before (Python)\ndef on_reset(self):\n    self.orders.clear()\n    self.indicator.reset()\n\n// after\ndef on_reset(self):\n    self.orders.clear()\n    if self.indicator is not None:\n        self.indicator.reset()","handlingStrategy":"try-catch","validationCode":"# verify all resettable attributes exist\nmissing = [a for a in ('orders', 'indicator') if not hasattr(self, a)]\nassert not missing, f'on_reset would fail, missing attrs: {missing}'","typeGuard":"def safe_reset(obj, name):\n    attr = getattr(obj, name, None)\n    return attr.reset() if hasattr(attr, 'reset') else None","tryCatchPattern":"def on_reset(self):\n    try:\n        ...  # clear state\n    except Exception as e:\n        self.log.error(f\"on_reset failed: {e}\")","preventionTips":["Create every resettable attribute in __init__ so reset never sees missing state.","Keep on_reset free of external I/O.","Run reset in your test teardown so it is exercised on every test run.","Use None checks before calling reset() on optional components."],"tags":["python","actor-lifecycle","callback-exception","rust-bridge"],"backgroundTag":"python-callback-raised-exception","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"}