QuantConnect/Lean · error · AssertionError
{call} should have returned {expected} ({type(expected)}) bu
Error message
{call} should have returned {expected} ({type(expected)}) but returned null What it means
Same check_parameter helper, expected-not-null branch (lines 38-39). It asserts that get_parameter returns a value (either the configured value or the supplied default) instead of None. A None return here means parameter lookup stopped applying defaults or stopped reading existing keys like 'ema-fast'.
Source
Thrown at Algorithm.Python/GetParameterRegressionAlgorithm.py:39
def initialize(self):
self.set_start_date(2013, 10, 7)
self.check_parameter(None, self.get_parameter("non-existing"), "GetParameter(\"non-existing\")")
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
- Verify the regression parameter config still defines ema-fast=10 (check Launcher/config and the regression test parameters).
- Inspect GetParameter(name, defaultValue) overloads: when key is absent the default must be returned (coerced to the requested type), not null.
- Confirm the algorithm receives its parameters dictionary during initialize (IAlgorithm.SetParameters / job parameters wiring).
Example fix
// before: default overload returns null
public int GetParameter(string name, int defaultValue) => null;
// after: return default when key missing
public int GetParameter(string name, int defaultValue)
=> _parameters.TryGetValue(name, out var v) && int.TryParse(v, out var i) ? i : defaultValue; Defensive patterns
Strategy: validation
Validate before calling
# ensure a value or default before use
ema = self.get_parameter("ema-fast", 10)
if ema is None:
raise RuntimeError("ema-fast parameter missing and no default applied") Prevention
- Always supply a default to get_parameter when the value is required.
- Validate required parameters at the start of initialize and fail loudly.
- Document expected parameter keys in the algorithm summary.
When it happens
Trigger: self.get_parameter("ema-fast") or self.get_parameter("non-existing", <default>) returns None. expected is non-None (the configured '10' / default), actual is None, so line 38-39 raises.
Common situations: The 'ema-fast' parameter was removed from the regression config; GetParameter default-argument overload regressed to always return null; parameters dictionary failed to load from the job/config.
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/411b543988c2b4b3.
Report an issue: GitHub.