{"record":{"id":"429f361c3a8cc694","repo":"nautechsystems/nautilus_trader","slug":"python-on-order-failed-e-429f36","errorCode":null,"errorMessage":"Python on_order failed: {e}","messagePattern":"Python on_order failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/python/algorithm.rs","lineNumber":393,"sourceCode":"    fn core_mut(&mut self) -> &mut DataActorCore {\n        DataActorNative::core_mut(&mut self.inner_mut().core)\n    }\n}\n\nimpl ExecutionAlgorithmNative for PyExecutionAlgorithm {\n    fn exec_algorithm_core(&self) -> &ExecutionAlgorithmCore {\n        &self.inner().core\n    }\n\n    fn exec_algorithm_core_mut(&mut self) -> &mut ExecutionAlgorithmCore {\n        &mut self.inner_mut().core\n    }\n}\n\nimpl ExecutionAlgorithm for PyExecutionAlgorithm {\n    fn on_order(&mut self, order: OrderAny) -> anyhow::Result<()> {\n        self.dispatch_on_order(order)\n            .map_err(|e| anyhow::anyhow!(\"Python on_order failed: {e}\"))\n    }\n\n    fn on_order_list(\n        &mut self,\n        order_list: OrderList,\n        orders: Vec<OrderAny>,\n    ) -> anyhow::Result<()> {\n        if self\n            .has_python_override(\"on_order_list\")\n            .map_err(|e| anyhow::anyhow!(\"Python override lookup failed: {e}\"))?\n        {\n            return self\n                .dispatch_on_order_list(order_list, orders)\n                .map_err(|e| anyhow::anyhow!(\"Python on_order_list failed: {e}\"));\n        }\n\n        for order in orders {\n            self.on_order(order)?;","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/python/algorithm.rs#L375-L411","documentation":"PyExecutionAlgorithm wraps a Python execution algorithm; when the Rust `ExecutionAlgorithm::on_order` trait method is invoked it dispatches into Python (`dispatch_on_order`). Any Python-side exception (or PyO3 boundary error) is re-wrapped as a Rust anyhow error with this message. It marks that the Python `on_order` callback itself failed, not the surrounding Rust pipeline.","triggerScenarios":"Calling on_order (directly or via on_order_list fallback loop) when the Python handler raises an exception, has a bad signature, or the interpreter/object reference is invalid.","commonSituations":"A bug in a user-written Python ExecutionAlgorithm.on_order override (TypeError, AttributeError, unhandled domain error); calling a removed/renamed Python method; Python callback expecting different argument types than the OrderAny conversion provides.","solutions":["Read the chained `{e}` message; it contains the original Python traceback/exception and fix the Python on_order implementation.","Reproduce the failing order in Python directly and run the on_order callback to get the full traceback.","Verify the Python class actually defines on_order with the expected signature for the current pyo3-asyncio/bindings version.","Confirm Python objects/imports are valid at construction time so the dispatch target exists."],"exampleFix":"// Python side\nclass MyAlgo(ExecutionAlgorithm):\n    def on_order(self, order):        # before: def on_order(self, order, ctx):  -> TypeError\n        ...","handlingStrategy":"try-catch","validationCode":"# Python: smoke-test the callback before registering the algorithm\nassert callable(getattr(algo, \"on_order\", None)), \"on_order override missing\"","typeGuard":"fn overrides_on_order(py_algo: &PyAny) -> pyo3::PyResult<bool> {\n    py_algo.call_method0(\"__class__\")?.getattr(\"on_order\")\n        .map(|_| true)\n}","tryCatchPattern":"match algo.on_order(order) {\n    Ok(()) => {},\n    Err(e) => log::error!(\"algorithm on_order failed: {e:#}\"), // {e} carries the Python traceback\n}","preventionTips":["Unit-test every Python ExecutionAlgorithm override in Python first with representative OrderAny data.","Keep Python callback signatures exactly as the bindings expect (single order argument).","Log the full anyhow chain ({e:#}) so the embedded Python traceback is visible."],"tags":["rust","python","pyo3","callback-failed","execution-algorithm"],"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"}