nautechsystems/nautilus_trader · error

Python on_reset failed: {e}

Error message

Python on_reset failed: {e}

What it means

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.

Source

Thrown at crates/trading/src/python/algorithm.rs:565

            .map_err(|e| anyhow::anyhow!("Python on_start failed: {e}"))
    }

    fn on_stop(&mut self) -> anyhow::Result<()> {
        ExecutionAlgorithm::on_stop(self)?;
        self.dispatch_no_args("on_stop")
            .map_err(|e| anyhow::anyhow!("Python on_stop failed: {e}"))
    }

    fn on_resume(&mut self) -> anyhow::Result<()> {
        ExecutionAlgorithm::on_resume(self)?;
        self.dispatch_no_args("on_resume")
            .map_err(|e| anyhow::anyhow!("Python on_resume failed: {e}"))
    }

    fn on_reset(&mut self) -> anyhow::Result<()> {
        ExecutionAlgorithm::on_reset(self)?;
        self.dispatch_no_args("on_reset")
            .map_err(|e| anyhow::anyhow!("Python on_reset failed: {e}"))
    }

    fn on_dispose(&mut self) -> anyhow::Result<()> {
        self.dispatch_no_args("on_dispose")
            .map_err(|e| anyhow::anyhow!("Python on_dispose failed: {e}"))
    }

    fn on_degrade(&mut self) -> anyhow::Result<()> {
        self.dispatch_no_args("on_degrade")
            .map_err(|e| anyhow::anyhow!("Python on_degrade failed: {e}"))
    }

    fn on_fault(&mut self) -> anyhow::Result<()> {
        self.dispatch_no_args("on_fault")
            .map_err(|e| anyhow::anyhow!("Python on_fault failed: {e}"))
    }

    fn on_time_event(&mut self, event: &TimeEvent) -> anyhow::Result<()> {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Read the chained `{e}` traceback and fix the Python on_reset implementation.
  2. Make on_reset defensive: use getattr/setdefault patterns so missing attributes don't raise.
  3. Ensure on_reset is only called on a live, initialized instance (check lifecycle order).
  4. Verify the zero-arg `def on_reset(self)` signature.

Example fix

// before
def on_reset(self):
    del self.orders  # AttributeError if never set

// after
def on_reset(self):
    self.orders = {}
Defensive patterns

Strategy: try-catch

Validate before calling

# Python: reset defensively
for attr in ("orders", "cache", "handlers"):
    if hasattr(self, attr): delattr(self, attr)

Try / catch

if let Err(e) = actor.on_reset() {
    log::error!("python on_reset failed: {e:#}"); // recreate the component if reset cannot clean state
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/49f493b8719cf74b. Report an issue: GitHub.