nautechsystems/nautilus_trader · error

Failed to get config class {config_class_name}: {e}

Error message

Failed to get config class {config_class_name}: {e}

What it means

Raised by `create_config_instance` when the Python module imported successfully but `getattr(module, config_class_name)` failed — i.e. the expected configuration class does not exist under that name in the module. The library needs the class object to instantiate the component config, so a missing attribute aborts node creation. The wrapped `{e}` is the underlying Python AttributeError.

Source

Thrown at crates/backtest/src/python/node.rs:521

        return Ok(None);
    }

    let config_parts: Vec<&str> = config_path.split(':').collect();
    if config_parts.len() != 2 {
        anyhow::bail!("config_path must be in format 'module.path:ClassName', was {config_path}");
    }
    let (config_module_name, config_class_name) = (config_parts[0], config_parts[1]);

    log::debug!(
        "Importing config class from module: {config_module_name} class: {config_class_name}"
    );

    let config_module = py
        .import(config_module_name)
        .map_err(|e| anyhow::anyhow!("Failed to import config module {config_module_name}: {e}"))?;
    let config_class = config_module
        .getattr(config_class_name)
        .map_err(|e| anyhow::anyhow!("Failed to get config class {config_class_name}: {e}"))?;

    // Convert config dict to Python dict
    let py_dict = PyDict::new(py);

    for (key, value) in config {
        let py_value = config_value_to_py(py, key, value)?;
        py_dict.set_item(key, py_value)?;
    }

    log::debug!("Created config dict: {py_dict:?}");

    // Try kwargs first, then default constructor with setattr
    let config_instance = match config_class.call((), Some(&py_dict)) {
        Ok(instance) => {
            log::debug!("Created config instance with kwargs");
            instance
        }
        Err(kwargs_err) => {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Verify the class name spelling and that it exists: `python -c "from <module> import <class>"`
  2. Update `config_class_name` after any rename, or import the class from the module where it is actually defined
  3. Ensure you are passing the bare class name (e.g. `MyStrategyConfig`) as the class argument, not a dotted `module.Class` string
  4. Check you imported the intended module — a same-named module shadowing the real one can hide the class

Example fix

// before
create_importable_component(py, config, module="my_pkg.strategy", class="MyStratConfig")
// after
create_importable_component(py, config, module="my_pkg.strategy", class="MyStrategyConfig")
Defensive patterns

Strategy: validation

Validate before calling

python -c "import <module>; assert hasattr(<module>, '<ConfigClass>')"

Try / catch

match create_config_instance(...) {
    Err(e) if e.to_string().contains("Failed to get config class") => {
        eprintln!("config class not found in module: {e:#}");
    }
    Err(e) => return Err(e),
    Ok(v) => v,
}

Prevention

When it happens

Trigger: `create_importable_component` is given a `config_class_name` string that is not an attribute of the imported module: misspelled class name, the class was renamed/moved to another module, or you passed the class's fully-qualified path in one string instead of splitting module and class.

Common situations: After a nautilus upgrade where config classes were renamed (e.g. `StrategyConfig` variations), a user config still references the old name; custom strategy configs defined in a different module than the one passed; passing a function or instance name instead of the config class name.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/430043672d11d078. Report an issue: GitHub.