QuantConnect/Lean · error · AssertionError
{call} should have returned {expected} ({type(expected)}) bu
Error message
{call} should have returned {expected} ({type(expected)}) but returned {actual} ({type(actual)}) What it means
check_parameter type/value mismatch branch (lines 41-42). Asserts get_parameter returns the expected value AND the same Python type. Fires on a wrong value or a type coercion bug (e.g. '10' string vs 10 int vs 10.0 float). Note the expression has loose operator precedence, but functionally it flags any value or type divergence from the expected.
Source
Thrown at Algorithm.Python/GetParameterRegressionAlgorithm.py:42
self.check_parameter("100", self.get_parameter("non-existing", "100"), "GetParameter(\"non-existing\", \"100\")")
self.check_parameter(100, self.get_parameter("non-existing", 100), "GetParameter(\"non-existing\", 100)")
self.check_parameter(100.0, self.get_parameter("non-existing", 100.0), "GetParameter(\"non-existing\", 100.0)")
self.check_parameter("10", self.get_parameter("ema-fast"), "GetParameter(\"ema-fast\")")
self.check_parameter(10, self.get_parameter("ema-fast", 100), "GetParameter(\"ema-fast\", 100)")
self.check_parameter(10.0, self.get_parameter("ema-fast", 100.0), "GetParameter(\"ema-fast\", 100.0)")
self.quit()
def check_parameter(self, expected, actual, call):
if expected == None and actual != None:
raise AssertionError(f"{call} should have returned null but returned {actual} ({type(actual)})")
if expected != None and actual == None:
raise AssertionError(f"{call} should have returned {expected} ({type(expected)}) but returned null")
if expected != None and actual != None and type(expected) != type(actual) or expected != actual:
raise AssertionError(f"{call} should have returned {expected} ({type(expected)}) but returned {actual} ({type(actual)})")
View on GitHub (pinned to d2c3659f87)
Solutions
- Confirm the regression config value for ema-fast is exactly '10' (string) and that the typed overloads coerce correctly to int 10 and float 10.0.
- Inspect each GetParameter<T> overload returns a T matching the requested type, not the raw stored string or the default's type.
- If you changed ema-fast intentionally, update the expected values in the check_parameter calls.
Example fix
// before: typed overload returns the raw string
public double GetParameter(string name, double defaultValue) => double.Parse(GetParameter(name));
// after: fall back to default when key missing, return double
public double GetParameter(string name, double defaultValue)
=> _parameters.TryGetValue(name, out var v) && double.TryParse(v, out var d) ? d : defaultValue; Defensive patterns
Strategy: type-guard
Validate before calling
# coerce and validate type explicitly
fast = self.get_parameter("ema-fast", 10)
if not isinstance(fast, int):
raise TypeError(f"ema-fast must be int, got {type(fast).__name__}: {fast!r}") Type guard
def as_int(algo, key: str, default: int) -> int:
v = algo.get_parameter(key, default)
return v if isinstance(v, int) else int(v)
def as_float(algo, key: str, default: float) -> float:
v = algo.get_parameter(key, default)
return v if isinstance(v, float) else float(v) Prevention
- Wrap get_parameter with typed coercion helpers instead of trusting the engine's return type.
- Pin parameter types in tests and assert isinstance.
- Keep the int vs float distinction explicit in defaults.
When it happens
Trigger: get_parameter returns a value whose type differs from expected (e.g. int where float expected) or whose value differs (e.g. ema-fast resolves to a number other than 10). The combined condition type(expected) != type(actual) or expected != actual is True.
Common situations: The int/float/string overload of get_parameter returns the wrong Python type after a refactor; the configured ema-fast value changed in config; default coercion returns the default's Python type instead of parsing the stored string into the requested type.
Related errors
- {call} should have returned null but returned {actual} ({typ
- {call} should have returned {expected} ({type(expected)}) bu
- Algorithm should have not run on extended hours for {self._g
- The total number of insights should be {expected}. Actual: {
- {} expected {}, but received {}
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/8059b9d10777028e.
Report an issue: GitHub.