{"record":{"id":"8ba6792267abae6e","repo":"nautechsystems/nautilus_trader","slug":"python-on-bar-failed-e","errorCode":null,"errorMessage":"Python on_bar failed: {e}","messagePattern":"Python on_bar failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1113,"sourceCode":"                .map_err(|e| anyhow::anyhow!(\"Failed to convert InstrumentAny to Python: {e}\"))?;\n            self.dispatch_on_instrument(py_instrument)\n                .map_err(|e| anyhow::anyhow!(\"Python on_instrument failed: {e}\"))\n        })\n    }\n\n    fn on_quote(&mut self, quote: &QuoteTick) -> anyhow::Result<()> {\n        self.dispatch_on_quote(*quote)\n            .map_err(|e| anyhow::anyhow!(\"Python on_quote failed: {e}\"))\n    }\n\n    fn on_trade(&mut self, tick: &TradeTick) -> anyhow::Result<()> {\n        self.dispatch_on_trade(*tick)\n            .map_err(|e| anyhow::anyhow!(\"Python on_trade failed: {e}\"))\n    }\n\n    fn on_bar(&mut self, bar: &Bar) -> anyhow::Result<()> {\n        self.dispatch_on_bar(*bar)\n            .map_err(|e| anyhow::anyhow!(\"Python on_bar failed: {e}\"))\n    }\n\n    fn on_book_deltas(&mut self, deltas: &OrderBookDeltas) -> anyhow::Result<()> {\n        self.dispatch_on_book_deltas(deltas.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_book_deltas failed: {e}\"))\n    }\n\n    fn on_book_depth(&mut self, depth: &OrderBookDepth10) -> anyhow::Result<()> {\n        self.dispatch_on_book_depth(depth)\n            .map_err(|e| anyhow::anyhow!(\"Python on_book_depth failed: {e}\"))\n    }\n\n    fn on_book(&mut self, order_book: &OrderBook) -> anyhow::Result<()> {\n        self.dispatch_on_book(order_book)\n            .map_err(|e| anyhow::anyhow!(\"Python on_book failed: {e}\"))\n    }\n\n    fn on_mark_price(&mut self, mark_price: &MarkPriceUpdate) -> anyhow::Result<()> {","sourceCodeStart":1095,"sourceCodeEnd":1131,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1095-L1131","documentation":"Wraps any failure raised when the Rust core dispatches a Bar into the Python actor's `on_bar` handler. The Python `on_bar` implementation raised (or the dispatch failed), and Rust re-raises it prefixed with 'Python on_bar failed'.","triggerScenarios":"A bar closes (subscribe_bars active) and the Python `on_bar(self, bar)` override raises an exception.","commonSituations":"Strategy signal logic in `on_bar` accessing indicators updated only for some bar types, wrong handler arity, or state machine bugs when a bar arrives out of expected sequence (gaps, session boundaries).","solutions":["Read the chained `{e}` traceback and fix the exception in `on_bar`","Confirm the signature `on_bar(self, bar)` and filter by `bar.bar_type` before strategy-specific logic","Handle bars for unexpected instruments/bar specs by early-returning rather than raising","Ensure indicators are registered/initialized before the first bar arrives"],"exampleFix":"// before\ndef on_bar(self, bar):\n    self.fast.update_bar(bar); self.slow.update_bar(bar)  # slow may be None\n// after\ndef on_bar(self, bar):\n    if self.slow is None:\n        return\n    self.fast.update_bar(bar); self.slow.update_bar(bar)","handlingStrategy":"try-catch","validationCode":"def _check_on_bar(self, bar):\n    try:\n        self.on_bar(bar)\n    except Exception as e:\n        self.log.error(f'on_bar failed: {e!r}')","typeGuard":null,"tryCatchPattern":"try:\n    self.dispatch_on_bar(bar)\nexcept Exception as e:\n    self.log.error(f'Python on_bar failed: {e}', exc_info=True)","preventionTips":["Filter bars by bar_type before strategy logic","Update all indicators for every bar type subscribed","Backtest with session gaps and partial data"],"tags":["python","actor","callback","bars"],"backgroundTag":"python-callback-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"}