Skip to content

Commit

Permalink
Merge pull request #880 from DFE-Digital/feat/234426/fix-dependencies…
Browse files Browse the repository at this point in the history
…-for-missing-sys-details

fix: Fix bug where dep collection fails if sys details are missing
  • Loading branch information
katie-gardner authored Nov 13, 2024
2 parents 222be68 + dfb347f commit 6c372e8
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 6c372e8

Please sign in to comment.