{"record":{"id":"bfa627c502b57d88","repo":"nautechsystems/nautilus_trader","slug":"python-feemodel-get-commission-failed-e","errorCode":null,"errorMessage":"Python FeeModel.get_commission failed: {e}","messagePattern":"Python FeeModel\\.get_commission failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/python/fee.rs","lineNumber":195,"sourceCode":"        &self,\n        order: &OrderAny,\n        fill_quantity: Quantity,\n        fill_px: Price,\n        instrument: &InstrumentAny,\n    ) -> anyhow::Result<Money> {\n        Python::attach(|py| -> anyhow::Result<Money> {\n            let order = order_any_to_pyobject(py, order.clone())?;\n            let instrument = instrument_any_to_pyobject(py, instrument.clone())?;\n            self.obj\n                .bind(py)\n                .call_method1(\n                    \"get_commission\",\n                    (order, fill_quantity, fill_px, instrument),\n                )?\n                .extract()\n                .map_err(|e| anyhow::anyhow!(\"{e}\"))\n        })\n        .map_err(|e| anyhow::anyhow!(\"Python FeeModel.get_commission failed: {e}\"))\n    }\n\n    fn get_commission_with_context(\n        &self,\n        order: &OrderAny,\n        fill_quantity: Quantity,\n        fill_px: Price,\n        instrument: &InstrumentAny,\n        underlying_px: Option<Price>,\n    ) -> anyhow::Result<Money> {\n        Python::attach(|py| -> anyhow::Result<Money> {\n            let obj = self.obj.bind(py);\n            if !has_method_override_before_base(py, obj, \"get_commission_with_context\")? {\n                let order = order_any_to_pyobject(py, order.clone())?;\n                let instrument = instrument_any_to_pyobject(py, instrument.clone())?;\n                return obj\n                    .call_method1(\n                        \"get_commission\",","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/python/fee.rs#L177-L213","documentation":"After the inner pyo3 call in the Python FeeModel wrapper fails, the outer `map_err` re-wraps whatever error occurred (including the `{e}` error from 3957) with the contextual message `Python FeeModel.get_commission failed: {e}`. It is the top-level context wrapper for failures of the Python-implemented `get_commission`.","triggerScenarios":"Any failure inside the wrapped Python `get_commission` call chain: Python exceptions, argument conversion failures, or result extraction errors when the Rust FFI calls the Python fee model.","commonSituations":"Custom Python fee models with incorrect signatures or return types; unconvertible Pythont/Rust object types; errors raised in user Python logic (division by zero, missing instrument attributes).","solutions":["Inspect the `{e}` portion for the root cause (usually the original Python exception text).","Fix the Python fee model signature: `get_commission(self, order, fill_quantity, fill_px, instrument)` returning a Money value.","Add try/except logging inside the Python model to capture and diagnose the failing input."],"exampleFix":"try:\n    fee = fee_model.get_commission(order, qty, px, instrument)\nexcept Exception as e:\n    logger.exception(\"fee model failed for %s\", instrument.id)\n    raise","handlingStrategy":"try-catch","validationCode":"assert callable(getattr(fee_model, 'get_commission', None)), \"FeeModel must implement get_commission\"","typeGuard":null,"tryCatchPattern":"match fee_model.get_commission(&order, qty, px, &instrument) {\n    Ok(fee) => fee,\n    Err(e) => {\n        // message is \"Python FeeModel.get_commission failed: <cause>\"\n        log::error!(\"{e}\"); fallback_flat_fee()\n    }\n}","preventionTips":["Treat the text after the prefix as the root Python exception and fix that.","Add defensive try/except and logging inside the Python fee model.","Test the fee model with real order/instrument objects before live use."],"tags":["python","pyo3","fee-model","ffi","rust"],"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"}