{"record":{"id":"ae92b06c40988459","repo":"QuantConnect/Lean","slug":"unexpected-distribution-distribution","errorCode":null,"errorMessage":"Unexpected distribution: {distribution}","messagePattern":"Unexpected distribution: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py","lineNumber":50,"sourceCode":"        if len(multi_symbol_request) != 12:\n                raise ValueError(f\"Unexpected multi symbol dividend count: {len(multi_symbol_request)}\")\n\n        # continuous future mapping requests\n        sp500 = Symbol.create(Futures.Indices.SP_500_E_MINI, SecurityType.FUTURE, Market.CME)\n        continuous_future_open_interest_mapping = self.history(SymbolChangedEvent, sp500, datetime(2007, 1, 1), datetime(2012, 1, 1), data_mapping_mode = DataMappingMode.OPEN_INTEREST)\n        if len(continuous_future_open_interest_mapping) != 9:\n                raise ValueError(f\"Unexpected continuous future mapping event count: {len(continuous_future_open_interest_mapping)}\")\n        continuous_future_last_trading_day_mapping = self.history(SymbolChangedEvent, sp500, datetime(2007, 1, 1), datetime(2012, 1, 1), data_mapping_mode = DataMappingMode.LAST_TRADING_DAY)\n        if len(continuous_future_last_trading_day_mapping) != 9:\n                raise ValueError(f\"Unexpected continuous future mapping event count: {len(continuous_future_last_trading_day_mapping)}\")\n\n        dividend = self.history(Dividend, aapl, 360)\n        self.debug(str(dividend))\n        if len(dividend) != 6:\n            raise ValueError(f\"Unexpected dividend count: {len(dividend)}\")\n        for distribution in dividend.distribution:\n            if distribution == 0:\n                raise ValueError(f\"Unexpected distribution: {distribution}\")\n\n        split = self.history(Split, aapl, 360)\n        self.debug(str(split))\n        if len(split) != 2:\n            raise ValueError(f\"Unexpected split count: {len(split)}\")\n        for splitfactor in split.splitfactor:\n            if splitfactor == 0:\n                raise ValueError(f\"Unexpected splitfactor: {splitfactor}\")\n\n        symbol = Symbol.create(\"BTCUSD\", SecurityType.CRYPTO_FUTURE, Market.BINANCE)\n        margin_interest = self.history(MarginInterestRate, symbol, 24 * 3, Resolution.HOUR)\n        self.debug(str(margin_interest))\n        if len(margin_interest) != 8:\n            raise ValueError(f\"Unexpected margin interest count: {len(margin_interest)}\")\n        for interestrate in margin_interest.interestrate:\n            if interestrate == 0:\n                raise ValueError(f\"Unexpected interestrate: {interestrate}\")\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py#L32-L68","documentation":"Per-row sanity check on the AAPL dividend history: every distribution value must be non-zero. A zero distribution indicates malformed dividend data (a dividend row with a 0 amount) or a deserialization bug that zeroed the distribution field.","triggerScenarios":"Iterating dividend.distribution, a value equals 0.0.","commonSituations":"A factor file row has a zero/blank distribution that was parsed as 0; a dividend refactor changed how Distribution is populated; data corruption.","solutions":["Inspect AAPL factor file rows in the window for zero or malformed distribution values.","Trace Dividend.Distribution population in the dividend reader/factor provider.","Correct or remove the bad data row and re-run."],"exampleFix":"# before: malformed factor row {time; priceFactor; splitFactor; 0 distribution}\n# after: corrected distribution value\n{20200713;1.0;1.0;0.205}","handlingStrategy":"validation","validationCode":"div = self.history(Dividend, aapl, 360)\nbad = [d for d in div.distribution if d == 0]\nif bad:\n    self.debug(f\"zero dividend distributions: {len(bad)}\")","typeGuard":"def has_nonzero_distributions(div_history) -> bool:\n    return all(d != 0 for d in div_history.distribution)","tryCatchPattern":null,"preventionTips":["Sanity-check auxiliary values, not just row counts.","Validate factor-file rows before relying on them.","Reject zero distributions at parse time in custom data readers."],"tags":["quantconnect","lean","regression","history","auxiliary-data","dividends","data-quality"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}