{"record":{"id":"c1a32ff6c202525c","repo":"nautechsystems/nautilus_trader","slug":"failed-to-set-attribute-key-setattr-err-c1a32f","errorCode":null,"errorMessage":"Failed to set attribute {key}: {setattr_err}","messagePattern":"Failed to set attribute (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/python/registration.rs","lineNumber":598,"sourceCode":"    let config_class = config_module\n        .getattr(config_class_name)\n        .map_err(|e| anyhow::anyhow!(\"Failed to get config class {config_class_name}: {e}\"))?;\n    let py_dict = PyDict::new(py);\n\n    for (key, value) in config {\n        let py_value = config_value_to_py(py, key, value)?;\n        py_dict.set_item(key, py_value)?;\n    }\n\n    let config_instance = match config_class.call((), Some(&py_dict)) {\n        Ok(instance) => instance,\n        Err(kwargs_err) => match config_class.call0() {\n            Ok(instance) => {\n                for (key, value) in config {\n                    let py_value = config_value_to_py(py, key, value)?;\n\n                    if let Err(setattr_err) = instance.setattr(key, py_value) {\n                        anyhow::bail!(\"Failed to set attribute {key}: {setattr_err}\");\n                    }\n                }\n\n                if instance.hasattr(\"__post_init__\")? {\n                    instance.call_method0(\"__post_init__\")?;\n                }\n\n                instance\n            }\n            Err(default_err) => {\n                anyhow::bail!(\n                    \"Failed to create config instance. Tried kwargs: {kwargs_err}, default: {default_err}\"\n                );\n            }\n        },\n    };\n\n    Ok(Some(config_instance))","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/python/registration.rs#L580-L616","documentation":"Fallback configuration path: when building the config object from keyword arguments fails, `create_config_instance` constructs a default instance and sets each config key as a Python attribute via setattr. If any setattr fails (typically because the config class has no such attribute or disallows attribute assignment), this error is raised naming the key and the underlying Python exception.","triggerScenarios":"Supplying a config dict key that does not correspond to any attribute/field of the target config class, or a class with __slots__/frozen semantics rejecting setattr; the kwargs constructor path already failed before this fallback ran.","commonSituations":"Typo'd or renamed config keys in JSON/YAML after a library version changed the config class fields; passing extra keys not defined on the NautilusTrader config dataclass; using a custom config class that rejects dynamic attributes.","solutions":["Fix or remove the config key named in the message so it matches a real field of the config class","Compare your config keys against the class definition (e.g. `MyConfig.__dataclass_fields__` or its signature) for the installed library version","Upgrade/downgrade so config keys match the library version's schema; check RELEASES.md for renamed fields","Prefer passing a matching kwargs dict so the constructor path succeeds and setattr is never used"],"exampleFix":"// before\nconfig = {\"bar_type\": ..., \"trade_size\": ..., \"insturment_id\": ...}  # typo\n// after\nconfig = {\"bar_type\": ..., \"trade_size\": ..., \"instrument_id\": ...}","handlingStrategy":"validation","validationCode":"import inspect\nvalid = set(inspect.signature(ConfigClass).parameters)\nbad = set(config.keys()) - valid\nassert not bad, f\"unknown config keys: {bad}\"","typeGuard":"def keys_match_config(config: dict, config_class) -> bool:\n    import inspect\n    params = set(inspect.signature(config_class).parameters)\n    return set(config) <= params","tryCatchPattern":"try:\n    trader.add_actor_from_importable_config(cfg)\nexcept ValueError as e:\n    if \"Failed to set attribute\" in str(e):\n        logger.error(\"unknown/mismatched config key: %s\", e)\n        raise ConfigError(str(e)) from e\n    raise","preventionTips":["Pin the library version and generate config keys from that version's schema","Run `inspect.signature(ConfigClass)` in CI to catch renamed/removed fields","Avoid typos by building config dicts programmatically from dataclass fields","Prefer constructing the config object in Python where typos fail fast as TypeError"],"tags":["rust","python","config","setattr"],"backgroundTag":"invalid-config-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"}