nautechsystems/nautilus_trader · error
Failed to get class {class_name}: {e}
Error message
Failed to get class {class_name}: {e} What it means
Fired when the Python module imported successfully but does not expose an attribute with the given class name while resolving an actor or strategy specification ('module.path:ClassName'). The input at fault is a registration field naming a class that does not exist in the specified module.
Source
Thrown at crates/system/src/python/registration.rs:549
if module_name.is_empty() || class_name.is_empty() || class_name.contains(':') {
anyhow::bail!("{field} must be in format 'module.path:ClassName'");
}
Ok((module_name, class_name))
}
fn import_python_class<'py>(
py: Python<'py>,
module_name: &str,
class_name: &str,
) -> anyhow::Result<Bound<'py, PyAny>> {
let module = py
.import(module_name)
.map_err(|e| anyhow::anyhow!("Failed to import module {module_name}: {e}"))?;
module
.getattr(class_name)
.map_err(|e| anyhow::anyhow!("Failed to get class {class_name}: {e}"))
}
fn create_config_instance<'py>(
py: Python<'py>,
config_path: &str,
config: &HashMap<String, serde_json::Value>,
) -> anyhow::Result<Option<Bound<'py, PyAny>>> {
if config_path.is_empty() && config.is_empty() {
log::debug!("No config_path or empty config, using None");
return Ok(None);
}
let Some((config_module_name, config_class_name)) = config_path.split_once(':') else {
anyhow::bail!("config_path must be in format 'module.path:ClassName', was {config_path}");
};
if config_module_name.is_empty()
|| config_class_name.is_empty()View on GitHub (pinned to 18893faf8b)
Solutions
- Check the class name in the config matches the exported class in the module exactly
- Open the module and confirm the class is defined (or re-exported) at the top level
- Update stale configs after renames
- Import the module interactively and `dir()` it to list available class names
Example fix
// before
{"strategy": "my_strategy.MomentumStrat"} # class renamed
// after
{"strategy": "my_strategy.MomentumStrategy"} Defensive patterns
Strategy: validation
Validate before calling
import importlib
mod = importlib.import_module(module_name)
assert hasattr(mod, class_name), f"{module_name} has no class {class_name}" Try / catch
try:
trader.add_strategy(strategy_config)
except Exception as e:
if "Failed to get class" in str(e):
logging.error("verify class name in config: %s", e)
raise Prevention
- Grep the module for `class <Name>` when writing configs
- Update configs whenever strategy classes are renamed
- Use editor autocomplete on the module to copy exact class names
When it happens
Trigger: Registering a Python actor/strategy with a `module:Class` string where the class name is misspelled, the class was renamed/moved to another module, or only an instance (not the class) is exposed under that name.
Common situations: Refactors renaming strategy classes while old JSON/YAML configs still reference the old name; referencing a function instead of a class; case mismatch (e.g. `myactor` vs `MyActor`).
Related errors
- Failed to get config class {config_class_name}: {e}
- Invalid `external_order_claims` type: {e}
- Invalid `external_order_claims` instrument ID {claim}: {e}
- BacktestEngineConfig.controller for importable controller '{
- config_path must be in format 'module.path:ClassName', was {
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/fe6cbbacf2128d4b.
Report an issue: GitHub.