{"record":{"id":"ad40ce24b35dd392","repo":"nautechsystems/nautilus_trader","slug":"python-on-pool-liquidity-update-failed-e","errorCode":null,"errorMessage":"Python on_pool_liquidity_update failed: {e}","messagePattern":"Python on_pool_liquidity_update failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1187,"sourceCode":"            .map_err(|e| anyhow::anyhow!(\"Python on_block failed: {e}\"))\n    }\n\n    #[cfg(feature = \"defi\")]\n    fn on_pool(&mut self, pool: &Pool) -> anyhow::Result<()> {\n        self.dispatch_on_pool(pool.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_pool failed: {e}\"))\n    }\n\n    #[cfg(feature = \"defi\")]\n    fn on_pool_swap(&mut self, swap: &PoolSwap) -> anyhow::Result<()> {\n        self.dispatch_on_pool_swap(swap.clone())\n            .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()","sourceCodeStart":1169,"sourceCodeEnd":1205,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1169-L1205","documentation":"Raised by `DataActor::on_pool_liquidity_update` (crates/common/src/python/actor.rs:1187) when dispatching a `PoolLiquidityUpdate` event to the Python actor fails. The dispatch invokes the Python instance's `on_pool_liquidity_update` method via pyo3's `call_method1`, so a Python exception in the handler, a missing method, or a conversion failure of the event to a Python object becomes `Python on_pool_liquidity_update failed: {e}`. It propagates Python-side handler failures into the Rust actor's error path.","triggerScenarios":"Fires when a `PoolLiquidityUpdate` (mint/burn liquidity event) arrives for a defi-enabled actor and the Python callback raises, the Python object lacks a callable `on_pool_liquidity_update`, or `update.into_py_any(py)` conversion fails.","commonSituations":"Handlers doing liquidity math (sqrt price, tick range, share valuation) hitting ZeroDivisionError or OverflowError; subscribing to pool liquidity updates without implementing the handler; version drift where the event field names changed; exceptions from external calls (web3 queries) inside the handler.","solutions":["Read the wrapped `{e}` cause for the original Python exception/traceback and fix the code inside your `on_pool_liquidity_update` handler.","Ensure the Python actor class implements `on_pool_liquidity_update(self, update)` if it subscribes to pool liquidity updates.","Guard arithmetic in the handler against zero/None values (e.g. liquidity, sqrt_price_x96) before computing.","Re-verify handler field access against the PoolLiquidityUpdate definition for your installed nautilus version."],"exampleFix":"# before: ZeroDivisionError on empty pool liquidity\ndef on_pool_liquidity_update(self, update):\n    price = update.sqrt_price_x96 ** 2 / update.liquidity\n\n# after\ndef on_pool_liquidity_update(self, update):\n    if not update.liquidity:\n        return\n    price = update.sqrt_price_x96 ** 2 / update.liquidity","handlingStrategy":"try-catch","validationCode":"assert callable(getattr(actor, 'on_pool_liquidity_update', None)), \"actor must implement on_pool_liquidity_update\"\n","typeGuard":"def has_liquidity_update_handler(obj):\n    return callable(getattr(obj, 'on_pool_liquidity_update', None))\n","tryCatchPattern":"try:\n    actor.on_pool_liquidity_update(update)\nexcept Exception as e:\n    log.error(f\"on_pool_liquidity_update failed: {e}\", exc_info=True)\n","preventionTips":["Guard division by liquidity/sqrt_price values against zero before math","Implement the handler whenever subscribing to pool liquidity updates","Test handlers with real historical PoolLiquidityUpdate payloads","Keep handler signatures aligned with the installed nautilus version"],"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"}