{"record":{"id":"ff67c14ee0638342","repo":"nautechsystems/nautilus_trader","slug":"failed-to-register-pystrategy-e","errorCode":null,"errorMessage":"Failed to register PyStrategy: {e}","messagePattern":"Failed to register PyStrategy: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/python/registration.rs","lineNumber":306,"sourceCode":"        &mut self,\n        strategy: &Py<PyAny>,\n        strategy_id: StrategyId,\n    ) -> anyhow::Result<()> {\n        let clock = self.create_component_clock(ComponentId::from(strategy_id));\n        let trader_id = self.trader_id;\n        let cache = self.cache.clone();\n        let portfolio = self.portfolio.clone();\n\n        Python::attach(|py| -> anyhow::Result<()> {\n            let py_strategy = strategy.bind(py);\n            let mut py_strategy_ref = py_strategy\n                .extract::<PyRefMut<PyStrategy>>()\n                .map_err(Into::<PyErr>::into)\n                .map_err(|e| anyhow::anyhow!(\"Failed to extract PyStrategy: {e}\"))?;\n\n            py_strategy_ref\n                .register(trader_id, clock, cache, portfolio)\n                .map_err(|e| anyhow::anyhow!(\"Failed to register PyStrategy: {e}\"))?;\n\n            log::debug!(\n                \"Internal PyStrategy registered: {}\",\n                py_strategy_ref.is_registered()\n            );\n\n            Ok(())\n        })?;\n\n        Python::attach(|py| -> anyhow::Result<()> {\n            let py_strategy = strategy.bind(py);\n            let py_strategy_ref = py_strategy\n                .cast::<PyStrategy>()\n                .map_err(|e| anyhow::anyhow!(\"Failed to downcast to PyStrategy: {e}\"))?;\n            py_strategy_ref.borrow().register_in_global_registries()?;\n            Ok(())\n        })?;\n","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/python/registration.rs#L288-L324","documentation":"After extraction succeeds, `register_python_strategy_components` calls the strategy's Rust `register(trader_id, clock, cache, portfolio)` and wraps any error it returns as this message. This fires when the strategy's own registration against trader/clock/cache/portfolio fails (e.g. invalid trader_id or a component-state error inside register).","triggerScenarios":"Calling `add_python_strategy_instance` where the strategy's internal `register` returns Err — e.g. malformed TraderId, a registration invariant inside PyStrategy failing, or a Python exception surfaced from the register path.","commonSituations":"Misconfigured trader_id in the node config; registering a strategy twice into the same trader; underlying clock/cache not initialized before adding strategies.","solutions":["Read the inner `{e}` for the precise failure inside PyStrategy::register.","Verify the trader_id and node configuration are valid and consistent.","Ensure each strategy instance is registered only once and the node's clock/cache/portfolio are initialized before adding strategies."],"exampleFix":"// before\nnode.trader.add_strategy(MyStrategy(StrategyConfig(strategy_id=\"invalid id!\")))\n\n// after\nfrom nautilus_trader.model.identifiers import StrategyId\nnode.trader.add_strategy(MyStrategy(StrategyConfig(strategy_id=StrategyId(\"MyStrategy-001\"))))","handlingStrategy":"validation","validationCode":"from nautilus_trader.model.identifiers import StrategyId\ncfg = MyStrategyConfig(strategy_id=StrategyId(\"MyStrategy-001\"))\nassert cfg.strategy_id and len(str(cfg.strategy_id)) > 0","typeGuard":null,"tryCatchPattern":"try:\n    trader.add_strategy(strategy)\nexcept Exception as e:\n    if \"Failed to register PyStrategy\" in str(e):\n        logging.error(\"register() failed inside strategy: %s — check trader_id/config\", e)\n    raise","preventionTips":["Validate strategy_id/trader_id formats before constructing the node.","Register each strategy instance exactly once.","Ensure the node's clock/cache/portfolio are initialized before adding strategies."],"tags":["python","strategy","registration","identifier"],"backgroundTag":"invalid-argument-value","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"}