{"record":{"id":"c5703f4e00c0ba40","repo":"nautechsystems/nautilus_trader","slug":"failed-to-create-config-instance-tried-kwargs-k","errorCode":null,"errorMessage":"Failed to create config instance. Tried kwargs: {kwargs_err}, default: {default_err}","messagePattern":"Failed to create config instance\\. Tried kwargs: (.+?), default: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/backtest/src/python/node.rs","lineNumber":562,"sourceCode":"                    log::debug!(\"Created default config instance, setting attributes\");\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                    // Only call __post_init__ if it exists (setattr path\n                    // needs it, kwargs path already triggered it via __init__)\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. \\\n                         Tried kwargs: {kwargs_err}, default: {default_err}\"\n                    );\n                }\n            }\n        }\n    };\n\n    log::debug!(\"Created config instance: {config_instance:?}\");\n\n    Ok(Some(config_instance))\n}\n\nfn config_value_to_py<'py>(\n    py: Python<'py>,\n    key: &str,\n    value: &serde_json::Value,\n) -> anyhow::Result<Bound<'py, PyAny>> {","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/python/node.rs#L544-L580","documentation":"create_config_instance attempts two construction paths: kwargs passed to the class constructor, then a default instance with attributes set. If BOTH fail, it bails with a combined message showing each path's error, so the developer can see why kwargs construction and default construction both failed.","triggerScenarios":"The config class import succeeds but the class cannot be constructed: required __init__ kwargs missing (kwargs_err) AND default construction fails, e.g. dataclass has required fields without defaults (default_err).","commonSituations":"Pointing config_path at a class that is not a NautilusTrader Config dataclass; version mismatch where the class gained a new required field; wrong class name importing an abstract base config.","solutions":["Read both sub-errors in the message: fix the kwargs_err first — supply all required constructor arguments","Verify the target class is a valid NautilusTrader Config dataclass with defaults for all fields","Check for version drift between your saved config and the installed nautilus_trader package","Construct the config in Python directly to get a clearer traceback, then adjust your serialized config"],"exampleFix":"// before\n\"config_path\": \"my.module:MyConfig\"  # MyConfig requires 'strategy_id' with no default\n// after\nconfig[\"strategy_id\"] = \"S-001\"  # or give MyConfig.strategy_id a default in Python","handlingStrategy":"validation","validationCode":"import dataclasses, inspect\ndef validate_config_constructible(config_cls, config: dict):\n    missing = [f.name for f in dataclasses.fields(config_cls)\n               if f.default is dataclasses.MISSING and f.default_factory is dataclasses.MISSING\n               and f.name not in config]\n    if missing:\n        raise ValueError(f\"{config_cls.__name__} missing required fields: {missing}\")\n    if not inspect.isclass(config_cls):\n        raise ValueError(\"config_path did not resolve to a class\")","typeGuard":null,"tryCatchPattern":"try:\n    instance = create_config_instance(config_cls, config)\nexcept Exception as e:\n    # message contains both kwargs_err and default_err\n    log.error(\"config construction failed (both paths): %s\", e)","preventionTips":["Ensure every config dataclass field has a default or is supplied in the config dict","Confirm config_path points at a concrete (non-abstract) Config subclass","Pin nautilus_trader versions between config serialization and backtest runs","Instantiate the config directly in Python first to get a clean traceback"],"tags":["rust","python","config","initialization"],"backgroundTag":"invalid-constructor-argument","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"}