{"record":{"id":"2737ba8787a58732","repo":"nautechsystems/nautilus_trader","slug":"failed-to-extract-pydataactor-e","errorCode":null,"errorMessage":"Failed to extract PyDataActor: {e}","messagePattern":"Failed to extract PyDataActor: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/python/registration.rs","lineNumber":430,"sourceCode":"    }\n\n    /// Gives `actor` its component clock and registers it in the global component, actor, and\n    /// wrapper registries.\n    fn register_python_data_actor(\n        &mut self,\n        actor: &Py<PyAny>,\n        component_id: ComponentId,\n    ) -> anyhow::Result<()> {\n        let clock = self.create_component_clock(component_id);\n        let trader_id = self.trader_id;\n        let cache = self.cache.clone();\n\n        Python::attach(|py| -> anyhow::Result<()> {\n            let py_actor = actor.bind(py);\n            let mut py_data_actor_ref = py_actor\n                .extract::<PyRefMut<PyDataActor>>()\n                .map_err(Into::<PyErr>::into)\n                .map_err(|e| anyhow::anyhow!(\"Failed to extract PyDataActor: {e}\"))?;\n\n            py_data_actor_ref\n                .register(trader_id, clock, cache)\n                .map_err(|e| anyhow::anyhow!(\"Failed to register PyDataActor: {e}\"))?;\n\n            log::debug!(\n                \"Internal PyDataActor registered: {}, state: {:?}\",\n                py_data_actor_ref.is_registered(),\n                py_data_actor_ref.state()\n            );\n\n            Ok(())\n        })?;\n\n        Python::attach(|py| -> anyhow::Result<()> {\n            let py_actor = actor.bind(py);\n            let py_data_actor_ref = py_actor\n                .cast::<PyDataActor>()","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/python/registration.rs#L412-L448","documentation":"`register_python_data_actor` extracts the actor as `PyRefMut<PyDataActor>` to register it with trader_id, clock, and cache. PyO3 extraction fails unless the Python object inherits the Rust-backed Actor base (`nautilus_trader.common.actor.Actor`), producing this error.","triggerScenarios":"Calling add_actor / add_exec_algorithm with a Python object whose class does not subclass the nautilus_trader `Actor` base — e.g. a plain class implementing callbacks, or an exec algorithm not built on Actor/Strategy bases.","commonSituations":"Custom data actors forgetting to inherit `Actor`; passing actor config instead of the actor instance; mixing actor classes from a different nautilus_trader build.","solutions":["Make the actor class inherit from `nautilus_trader.common.actor.Actor` (or the appropriate Strategy base for exec algorithms).","Pass the instantiated actor object, not the class or its config.","Align the actor's defining module with the active nautilus_trader installation (single version)."],"exampleFix":"// before\nclass MyActor:\n    def on_start(self): ...\n\n// after\nfrom nautilus_trader.common.actor import Actor\n\nclass MyActor(Actor):\n    def on_start(self): ...","handlingStrategy":"type-guard","validationCode":"from nautilus_trader.common.actor import Actor\nassert isinstance(my_actor, Actor), \"actor must subclass Actor\"","typeGuard":"def is_actor(obj) -> bool:\n    from nautilus_trader.common.actor import Actor\n    return isinstance(obj, Actor)","tryCatchPattern":"try:\n    trader.add_actor(actor)\nexcept Exception as e:\n    if \"Failed to extract PyDataActor\" in str(e):\n        raise TypeError(f\"{type(actor).__name__} must subclass nautilus_trader Actor\") from e\n    raise","preventionTips":["Always subclass nautilus_trader.common.actor.Actor for data actors.","Use the appropriate base (Actor vs Strategy) for actors vs exec algorithms.","Assert isinstance in factory code that constructs actors from config."],"tags":["python","pyo3","actor","type-mismatch"],"backgroundTag":"type-mismatch","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"}