QuantConnect/Lean · error · RegressionTestException
Unexpected Bar error
Error message
Unexpected Bar error
What it means
This RegressionTestException is thrown in OnData when the universe is selected (_universeSelected == true). It asserts that the single bar in slice.Bars is NOT a fill-forward bar and has a period of exactly 1 minute. LEAN throws it because when the universe selects SPY at Minute resolution while the AddEquity subscription is at Hour resolution, the universe-driven data should deliver real (non-fill-forward) Minute bars.
Source
Thrown at Algorithm.CSharp/CustomUniverseWithBenchmarkRegressionAlgorithm.cs:90
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
var security = Securities[_spy];
_onDataWasCalled = true;
var bar = slice.Bars.Values.Single();
if (_universeSelected)
{
if (bar.IsFillForward
|| bar.Period != TimeSpan.FromMinutes(1))
{
// bar should always be the Minute resolution one here
throw new RegressionTestException("Unexpected Bar error");
}
if (_previousTime.Date == slice.Time.Date
&& (slice.Time - _previousTime) != TimeSpan.FromMinutes(1))
{
throw new RegressionTestException("For the same date expected data updates every 1 minute");
}
}
else
{
if (slice.Time.Minute == 0
&& _previousSecurityValue == security.Price)
{
throw new RegressionTestException($"Security Price error. Price should change every new hour");
}
if (slice.Time.Minute != 0
&& _previousSecurityValue != security.Price
&& security.IsTradable)
{View on GitHub (pinned to d2c3659f87)
Solutions
- Log bar.IsFillForward and bar.Period at the throw point to determine which condition failed.
- Trace the subscription data-feed configuration to confirm the universe's Minute resolution is not being collapsed to Hour by the existing AddEquity(Hour) subscription.
- Check that fill-forward only triggers on actual market gaps, not due to missing data files.
- If testing engine changes, verify the SubscriptionDataConfig priority/merge logic preserves the highest-resolution subscription.
Example fix
// before
if (bar.IsFillForward || bar.Period != TimeSpan.FromMinutes(1))
{
throw new RegressionTestException("Unexpected Bar error");
}
// after — split conditions for diagnosis
if (bar.IsFillForward)
throw new RegressionTestException($"Bar was fill-forward, expected real data. Time: {slice.Time}");
if (bar.Period != TimeSpan.FromMinutes(1))
throw new RegressionTestException($"Bar period was {bar.Period}, expected 1 minute. Time: {slice.Time}"); Defensive patterns
Strategy: validation
Validate before calling
// Validate bar properties before asserting
var bar = slice.Bars.Values.Single();
if (bar.IsFillForward)
Log($"Fill-forward bar at {slice.Time} — check data availability");
if (bar.Period != TimeSpan.FromMinutes(1))
Log($"Bar period {bar.Period} — resolution may not be Minute"); Prevention
- When mixing AddEquity(Hour) with a Minute-resolution universe, verify the engine preserves the higher resolution for universe-selected data.
- Check data files exist at the expected resolution to avoid fill-forward.
- Log bar.IsFillForward during development to detect data gaps.
When it happens
Trigger: bar.IsFillForward is true (the engine filled forward a stale bar instead of delivering real minute data), or bar.Period != 1 minute (the resolution was not correctly upgraded from Hour to Minute when the universe selected the security). Both indicate the universe subscription's resolution override isn't working.
Common situations: A LEAN version change to subscription resolution merging logic caused the minute-resolution universe subscription to be overridden by the hour-resolution AddEquity subscription. Also occurs when fill-forward logic changed to be more aggressive, or when universe-selection data-feed configuration was refactored.
Related errors
- Expected {ExpectedSymbols.Count} stocks to be added to the a
- Expected symbols were not added to the algorithm
- Expected events didn't happen
- For the same date expected data updates every 1 minute
- Security Price error. Price should change every new hour
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/2b41bab09aae11a9.
Report an issue: GitHub.