{"record":{"id":"4bad996501830888","repo":"QuantConnect/Lean","slug":"call-should-have-returned-null-but-returned-act","errorCode":null,"errorMessage":"{call} should have returned null but returned {actual} ({type(actual)})","messagePattern":"(.+?) should have returned null but returned (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/GetParameterRegressionAlgorithm.py","lineNumber":36,"sourceCode":"### </summary>\nclass GetParameterRegressionAlgorithm(QCAlgorithm):\n\n    def initialize(self):\n        self.set_start_date(2013, 10, 7)\n        self.check_parameter(None, self.get_parameter(\"non-existing\"), \"GetParameter(\\\"non-existing\\\")\")\n        self.check_parameter(\"100\", self.get_parameter(\"non-existing\", \"100\"), \"GetParameter(\\\"non-existing\\\", \\\"100\\\")\")\n        self.check_parameter(100, self.get_parameter(\"non-existing\", 100), \"GetParameter(\\\"non-existing\\\", 100)\")\n        self.check_parameter(100.0, self.get_parameter(\"non-existing\", 100.0), \"GetParameter(\\\"non-existing\\\", 100.0)\")\n\n        self.check_parameter(\"10\", self.get_parameter(\"ema-fast\"), \"GetParameter(\\\"ema-fast\\\")\")\n        self.check_parameter(10, self.get_parameter(\"ema-fast\", 100), \"GetParameter(\\\"ema-fast\\\", 100)\")\n        self.check_parameter(10.0, self.get_parameter(\"ema-fast\", 100.0), \"GetParameter(\\\"ema-fast\\\", 100.0)\")\n\n        self.quit()\n\n    def check_parameter(self, expected, actual, call):\n        if expected == None and actual != None:\n            raise AssertionError(f\"{call} should have returned null but returned {actual} ({type(actual)})\")\n\n        if expected != None and actual == None:\n            raise AssertionError(f\"{call} should have returned {expected} ({type(expected)}) but returned null\")\n\n        if expected != None and actual != None and type(expected) != type(actual) or expected != actual:\n            raise AssertionError(f\"{call} should have returned {expected} ({type(expected)}) but returned {actual} ({type(actual)})\")\n","sourceCodeStart":18,"sourceCodeEnd":43,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/GetParameterRegressionAlgorithm.py#L18-L43","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the algorithm's parameters source (Launcher/config parameters.json or the backtest job parameters) does not contain the key 'non-existing'.","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.","Re-run with the stock regression config to confirm the leak is from code, not config."],"exampleFix":"// before: no-default overload leaks a default\npublic string GetParameter(string name) => _parameters.GetValueOrDefault(name, string.Empty);\n// after: null on miss\npublic string GetParameter(string name) => _parameters.TryGetValue(name, out var v) ? v : null;","handlingStrategy":"validation","validationCode":"# guard before relying on a parameter that should be absent\nkey = \"non-existing\"\nval = self.get_parameter(key)\nif key not in (self.get_parameter(\"__keys__\") or \"\") and val is not None:\n    self.debug(f\"unexpected value for absent parameter {key}: {val!r}\")","typeGuard":"def is_none_on_miss(algo, key: str) -> bool:\n    return algo.get_parameter(key) is None","tryCatchPattern":null,"preventionTips":["Treat parameters as untrusted input; check existence before use.","Use the typed default overload (get_parameter(name, default)) when a fallback is acceptable.","Keep regression parameter config minimal and deterministic."],"tags":["quantconnect","lean","regression","parameters","get-parameter"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}