Skip to content

Commit

Permalink
fix: Fix bug where dep collection fails if sys details are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
katie-gardner committed Nov 13, 2024
1 parent 222be68 commit dfb347f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Dfe.PlanTech.Infrastructure.Redis/RedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,17 @@ private async Task<IEnumerable<string>> GetDependenciesAsync<T>(T value)
/// <param name="value"></param>
private async Task<IEnumerable<string>> GetContentDependenciesAsync(ContentComponent value)
{
// RichText is a sub-component that doesn't have SystemDetails, exit for such types
if (value.Sys is null)
return [];

// add the item itself as a dependency
var results = new List<string> { value.Sys.Id };

var properties = value.GetType().GetProperties();
foreach (var property in properties)
{
if (property.PropertyType == typeof(ContentComponent) || typeof(IEnumerable<ContentComponent>).IsAssignableFrom(property.PropertyType))
if (typeof(ContentComponent).IsAssignableFrom(property.PropertyType) || typeof(IEnumerable<ContentComponent>).IsAssignableFrom(property.PropertyType))
{
var nestedDependencies = await GetDependenciesAsync(property.GetValue(value));
results.AddRange(nestedDependencies);
Expand Down

0 comments on commit dfb347f

Please sign in to comment.