QuantConnect/Lean · error · AssertionError

{call} should have returned null but returned {actual} ({typ

Error message

{call} should have returned null but returned {actual} ({type(actual)})

What it means

Thrown by the parameter-check helper in GetParameterRegressionAlgorithm. With expected=None it asserts that QCAlgorithm.get_parameter(name) with no default returns None for a key that does not exist in the algorithm parameters. If the engine returns a value for a non-existent key, parameter resolution is broken (e.g. a default is leaking, the parameters dictionary was mis-populated, or get_parameter stopped returning None on miss).

Source

Thrown at Algorithm.Python/GetParameterRegressionAlgorithm.py:36

### </summary>
class GetParameterRegressionAlgorithm(QCAlgorithm):

    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

  1. Check the algorithm's parameters source (Launcher/config parameters.json or the backtest job parameters) does not contain the key 'non-existing'.
  2. Inspect IAlgorithm.GetParameter(string) in Common/Algorithm: it must return null when the key is absent and no default was supplied; the default-overload must only apply when a default argument is passed.
  3. Re-run with the stock regression config to confirm the leak is from code, not config.

Example fix

// before: no-default overload leaks a default
public string GetParameter(string name) => _parameters.GetValueOrDefault(name, string.Empty);
// after: null on miss
public string GetParameter(string name) => _parameters.TryGetValue(name, out var v) ? v : null;
Defensive patterns

Strategy: validation

Validate before calling

# guard before relying on a parameter that should be absent
key = "non-existing"
val = self.get_parameter(key)
if key not in (self.get_parameter("__keys__") or "") and val is not None:
    self.debug(f"unexpected value for absent parameter {key}: {val!r}")

Type guard

def is_none_on_miss(algo, key: str) -> bool:
    return algo.get_parameter(key) is None

Prevention

When it happens

Trigger: Calling self.get_parameter("non-existing") (no default arg) returns a non-None value. The check_parameter(expected=None, actual=..., call=...) branch at line 35-36 fires because actual != None.

Common situations: Regression in IAlgorithm.GetParameter after refactoring parameter lookup; a backtest parameters file (parameters.json) now contains the key 'non-existing'; merge of a default-value fallback into the no-default overload so misses never return None.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/4bad996501830888. Report an issue: GitHub.