Skip to content

Commit 0cd979f

Browse files
authored
Solve bug in ETFConstituentsUniverseSelectionModel (#7724)
* Fix bug in ETFConstituentUniverseSelectionModel() The bug was raised after calling an overload constructor using just the ticker as parameter. Since the universeFilterFunc was null, the method Extensions.TryConvertToDelegate<T> returned true and thus, the filter func assigned was the one returned by the method `ConvertToUniverseSelectionSymbolDelegate()` which used the null filterfunc. * Handle potential future bugs
1 parent 3a9059a commit 0cd979f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Common/Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ public static Func<IEnumerable<T>, IEnumerable<Symbol>> ConvertPythonUniverseFil
26972697
Func<IEnumerable<T>, object> convertedFunc;
26982698
Func<IEnumerable<T>, IEnumerable<Symbol>> filterFunc = null;
26992699

2700-
if (universeFilterFunc.TryConvertToDelegate(out convertedFunc))
2700+
if (universeFilterFunc != null && universeFilterFunc.TryConvertToDelegate(out convertedFunc))
27012701
{
27022702
filterFunc = convertedFunc.ConvertToUniverseSelectionSymbolDelegate();
27032703
}

Tests/Algorithm/Framework/Selection/ETFConstituentsUniverseSelectionModelTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Collections.Generic;
2323
using QuantConnect.Data.UniverseSelection;
2424
using QuantConnect.Algorithm.Framework.Selection;
25+
using Moq;
2526

2627
namespace QuantConnect.Tests.Algorithm.Framework.Selection
2728
{
@@ -165,6 +166,8 @@ public void ETFConstituentsUniverseSelectionModelTestAllConstructor()
165166

166167
Assert.AreEqual(symbol.SecurityType, universe.Configuration.Symbol.SecurityType);
167168
Assert.IsTrue(universe.Configuration.Symbol.ID.Symbol.StartsWithInvariant("qc-universe-"));
169+
var data = new Mock<BaseDataCollection>();
170+
Assert.DoesNotThrow(() => universe.PerformSelection(DateTime.UtcNow, data.Object));
168171

169172
} while (++numberOfOperation <= 9) ;
170173
}

0 commit comments

Comments
 (0)