{"record":{"id":"4ff6b987ad4d6aa2","repo":"QuantConnect/Lean","slug":"unexpected-data-count-datacount-expected-13","errorCode":null,"errorMessage":"Unexpected data count {_dataCount}. Expected 13","messagePattern":"Unexpected data count (.+?)\\. Expected 13","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DelistingEventsAlgorithm.cs","lineNumber":135,"sourceCode":"                {\n                    _receivedSecurityChangesEvent++;\n                }\n            }\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (!_receivedDelistedEvent)\n            {\n                throw new RegressionTestException(\"Did not receive expected delisted event\");\n            }\n            if (!_receivedDelistedWarningEvent)\n            {\n                throw new RegressionTestException(\"Did not receive expected delisted warning event\");\n            }\n            if (_dataCount != 13)\n            {\n                throw new RegressionTestException($\"Unexpected data count {_dataCount}. Expected 13\");\n            }\n            if (_receivedSecurityChangesEvent != 1)\n            {\n                throw new RegressionTestException($\"Did not receive expected security changes removal! Got {_receivedSecurityChangesEvent}\");\n            }\n        }\n\n        /// <summary>\n        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.\n        /// </summary>\n        public bool CanRunLocally { get; } = true;\n\n        /// <summary>\n        /// This is used by the regression test system to indicate which languages this algorithm is written in.\n        /// </summary>\n        public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };\n\n        /// <summary>","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DelistingEventsAlgorithm.cs#L117-L153","documentation":"Asserted in OnEndOfAlgorithm of a delisting regression that trades AAA.1 and SPY at daily resolution from 2007-05-15 to 2007-05-25. _dataCount accumulates slice.Bars.Count across every OnData call and must equal exactly 13. A mismatch signals that the data feed delivered a different number of trade bars than the fixture expects (e.g., delisting/removed bars, missing data files, or a changed date range).","triggerScenarios":"Running the regression when the AAA.1 or SPY daily data for the 2007-05-15..2007-05-25 window is missing, corrupted, or augmented with extra bars. Any change to SetStartDate/SetEndDate or AddSecurity resolution also shifts the accumulated count.","commonSituations":"Local data store missing the specific delisting-period files for AAA.1, a Lean data-reading change that adds/removes a bar (e.g., handling of the delisting day itself), or editing the date range without updating the expected literal 13.","solutions":["Confirm the AAA.1 and SPY daily factor files exist under the data folder for 2007-05-15 through 2007-05-25.","Run with the exact dates from Initialize (2007-05-15 to 2007-05-25) — do not modify SetStartDate/SetEndDate without recalculating the expected count.","If the count legitimately changed due to a Lean data-handling fix, update the literal 13 to the new verified value and document why.","Temporarily log _dataCount per OnData call to identify which date contributes an unexpected bar."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Track and assert data count with a descriptive message\nif (_dataCount != 13)\n{\n    throw new InvalidOperationException(\n        $\"Data count {_dataCount} != 13; check AAA.1/SPY daily data for the backtest window\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the backtest date range and data files so the expected bar count is stable.","Log per-day bar counts during development to catch data gaps early.","Update the expected literal only after verifying the data feed with a fresh data download."],"tags":["quantconnect","delisting","data-count","regression-test","equity"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}