{"record":{"id":"d473af7dc04dd567","repo":"nautechsystems/nautilus_trader","slug":"python-on-pool-flash-failed-e","errorCode":null,"errorMessage":"Python on_pool_flash failed: {e}","messagePattern":"Python on_pool_flash failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1199,"sourceCode":"            .map_err(|e| anyhow::anyhow!(\"Python on_pool_swap failed: {e}\"))\n    }\n\n    #[cfg(feature = \"defi\")]\n    fn on_pool_liquidity_update(&mut self, update: &PoolLiquidityUpdate) -> anyhow::Result<()> {\n        self.dispatch_on_pool_liquidity_update(update.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_pool_liquidity_update failed: {e}\"))\n    }\n\n    #[cfg(feature = \"defi\")]\n    fn on_pool_fee_collect(&mut self, collect: &PoolFeeCollect) -> anyhow::Result<()> {\n        self.dispatch_on_pool_fee_collect(collect.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_pool_fee_collect failed: {e}\"))\n    }\n\n    #[cfg(feature = \"defi\")]\n    fn on_pool_flash(&mut self, flash: &PoolFlash) -> anyhow::Result<()> {\n        self.dispatch_on_pool_flash(flash.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_pool_flash failed: {e}\"))\n    }\n\n    fn on_historical_data(&mut self, data: &dyn Any) -> anyhow::Result<()> {\n        Python::attach(|py| {\n            let py_data: Py<PyAny> = if let Some(custom_data) = data.downcast_ref::<CustomData>() {\n                Py::new(py, custom_data.clone())?.into_any()\n            } else if let Some(custom_data) = data.downcast_ref::<Vec<CustomData>>() {\n                custom_data.clone().into_py_any(py)?\n            } else {\n                anyhow::bail!(\"Failed to convert historical data to Python: unsupported type\");\n            };\n            self.dispatch_on_historical_data(py_data)\n                .map_err(|e| anyhow::anyhow!(\"Python on_historical_data failed: {e}\"))\n        })\n    }\n\n    fn on_historical_book_deltas(&mut self, deltas: &[OrderBookDelta]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_book_deltas(deltas.to_vec())","sourceCodeStart":1181,"sourceCodeEnd":1217,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1181-L1217","documentation":"Raised by `DataActor::on_pool_flash` (crates/common/src/python/actor.rs:1199) when dispatching a `PoolFlash` (flash-loan) event to the Python actor's `on_pool_flash` callback fails. `dispatch_on_pool_flash` calls the Python method via pyo3 `call_method1`; a Python exception in the handler, a missing method, or conversion of the event via `into_py_any` failing is wrapped as `Python on_pool_flash failed: {e}`.","triggerScenarios":"Occurs when a pool flash-loan event reaches a defi-enabled actor and the Python callback raises, the Python instance lacks a callable `on_pool_flash`, or `flash.into_py_any(py)` conversion errors.","commonSituations":"Flash-loan arbitrage handlers raising on unexpected amounts/tokens; missing handler on a class that subscribes to flash events; protocol-specific parsing bugs (e.g. Aave/Uniswap flash payloads); version drift in event schema.","solutions":["Unwrap the `{e}` cause to see the original Python exception and fix the `on_pool_flash` handler code.","Ensure the Python actor implements `on_pool_flash(self, flash)` when subscribing to flash events.","Add validation of flash amounts/tokens in the handler and short-circuit on unexpected values.","Check the PoolFlash type definition for your nautilus version and update handler field access after upgrades."],"exampleFix":"# before\ndef on_pool_flash(self, flash):\n    profit = self.value_received(flash) - self.value_owed(flash)\n    self.submit_order(self.build_arb(profit))  # raises if profit < 0\n\n# after\ndef on_pool_flash(self, flash):\n    profit = self.value_received(flash) - self.value_owed(flash)\n    if profit <= 0:\n        self.log.info(f\"No arb in flash event: {profit}\")\n        return\n    self.submit_order(self.build_arb(profit))","handlingStrategy":"try-catch","validationCode":"assert callable(getattr(actor, 'on_pool_flash', None)), \"actor must implement on_pool_flash\"\n","typeGuard":"def has_flash_handler(obj):\n    return callable(getattr(obj, 'on_pool_flash', None))\n","tryCatchPattern":"try:\n    actor.on_pool_flash(flash)\nexcept Exception as e:\n    log.error(f\"on_pool_flash failed: {e}\", exc_info=True)\n","preventionTips":["Validate flash amounts and tokens before arbitrage logic","Never assume profitability; branch on computed profit explicitly","Test flash handlers against recorded PoolFlash payloads","Implement the handler on every actor that subscribes to flash events"],"tags":["python","defi","callback","pyo3","rust"],"backgroundTag":"api-request-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"}