{"record":{"id":"ea4abdb1e183432b","repo":"nautechsystems/nautilus_trader","slug":"invalid-actor-id-type","errorCode":null,"errorMessage":"Invalid `actor_id` type","messagePattern":"Invalid `actor_id` type","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":2855,"sourceCode":"    config: Option<&Bound<'_, PyAny>>,\n) -> anyhow::Result<ActorId> {\n    let mut actor = actor_obj\n        .extract::<PyRefMut<PyDataActor>>()\n        .map_err(Into::<PyErr>::into)\n        .map_err(|e| anyhow::anyhow!(\"Failed to extract PyDataActor: {e}\"))?;\n\n    if let Some(config) = config {\n        if let Some(actor_id) = config\n            .getattr(\"actor_id\")\n            .ok()\n            .filter(|actor_id| !actor_id.is_none())\n        {\n            let actor_id = if let Ok(actor_id) = actor_id.extract::<ActorId>() {\n                actor_id\n            } else if let Ok(actor_id) = actor_id.extract::<String>() {\n                ActorId::new_checked(&actor_id)?\n            } else {\n                anyhow::bail!(\"Invalid `actor_id` type\");\n            };\n            actor.set_actor_id(actor_id);\n        }\n\n        if let Some(log_events) = extract_bool_config_attr(config, \"log_events\") {\n            actor.set_log_events(log_events);\n        }\n\n        if let Some(log_commands) = extract_bool_config_attr(config, \"log_commands\") {\n            actor.set_log_commands(log_commands);\n        }\n    }\n\n    actor.set_python_instance(actor_obj)?;\n    apply_class_derived_actor_id(&mut actor, actor_obj)?;\n    Ok(actor.actor_id())\n}\n","sourceCodeStart":2837,"sourceCodeEnd":2873,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L2837-L2873","documentation":"When configuring an actor from Python, the `actor_id` attribute must be either an ActorId instance or a string parseable into one. If the Python object extracts as neither, the builder bails with this message. The library throws it to fail fast on a mistyped identifier rather than silently assigning a default.","triggerScenarios":"Passing `actor_id` in the actor config as something other than ActorId or str — e.g. an int, UUID object, None, or bytes — while constructing/registered a Python actor.","commonSituations":"Using a numeric or UUID id from another system as actor_id; YAML/JSON config where actor_id was loaded as an int; leaving actor_id set to None expecting it to be auto-generated.","solutions":["Pass actor_id as a string, e.g. actor_id=\"MyActor-001\", or as an ActorId instance.","Omit actor_id entirely to let the system assign one automatically.","Coerce non-string ids to str before building the config."],"exampleFix":"// before\nconfig = MyActorConfig(actor_id=42)\n// after\nconfig = MyActorConfig(actor_id=\"42\")","handlingStrategy":"validation","validationCode":"actor_id = config.get(\"actor_id\")\nif actor_id is not None and not isinstance(actor_id, (ActorId, str)):\n    raise TypeError(f\"actor_id must be ActorId or str, got {type(actor_id).__name__}\")","typeGuard":"def is_valid_actor_id(v) -> bool:\n    return isinstance(v, (ActorId, str))","tryCatchPattern":"try:\n    factory.create(config)\nexcept Exception as e:\n    if \"Invalid `actor_id` type\" in str(e):\n        config[\"actor_id\"] = str(config[\"actor_id\"])\n        factory.create(config)","preventionTips":["Always express actor ids as strings in configs and code.","Coerce numeric/UUID ids with str(...) when importing from external systems.","Omit actor_id when you want auto-assignment rather than passing None."],"tags":["python","type-mismatch","actor-id","config"],"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"}