Skip to content

Commit

Permalink
Added early exit out of recursive settings expansion. Also added addi…
Browse files Browse the repository at this point in the history
…tional documentation regarding deployment pipelines and settings (statiqdev/Statiq.Web#1020).
  • Loading branch information
daveaglick committed Jan 5, 2024
1 parent a0eb115 commit c14b82c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.0-beta.72

- Added an improved warning message and early exit out of recursive settings expansion.

# 1.0.0-beta.71

- Modified the behavior of computed metadata values to cache the value for a given document when using the `=>` prefix. The previous behavior that evaluates a computed value every time it's accessed can still be used by prefixing with `->` instead. In theory this change shouldn't result in any differences in behavior since documents are immutable in the first place (so caching wouldn't be any different from re-evaluating), but if you have computed metadata values that consider state outside the document (such as something like `DateTime.Now`), you'll need to switch those to use the `->` prefix instead.
Expand Down
27 changes: 19 additions & 8 deletions src/core/Statiq.Common/Meta/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,28 @@ public static object ExpandValue(string key, object value, IMetadata metadata)
// Perform special expansions of IMetadataValue
if (value is IMetadataValue metadataValue)
{
// Warn if this looks like a recursive call
// Warn if this looks like a recursive call, and exit if we get here again
(string, IMetadataValue, int) expanding = (key, metadataValue, Thread.CurrentThread.ManagedThreadId);
if (!_expandingWarned.Contains(expanding) && !_expanding.Add(expanding))
if (!_expanding.Add(expanding))
{
string displayString = (metadata as IDocument)?.ToSafeDisplayString();
if (displayString is object)
if (!_expandingWarned.Contains(expanding))
{
displayString = " (" + displayString + ")";
// First time so log a warning and continue trying to expand
string displayString = (metadata as IDocument)?.ToSafeDisplayString();
if (displayString is object)
{
displayString = " (" + displayString + ")";
}

IExecutionContext.Current.LogWarning(
$"Potential recursive metadata expansion detected for key {key}{displayString}, is an actual value for the key properly defined somewhere?");
_expandingWarned.Add(expanding);
}
else
{
// Second time, so return a default value
return default;
}
IExecutionContext.Current.LogWarning("Potential recursive metadata expansion detected for key " + key + displayString);
_expandingWarned.Add(expanding);
}

// Expand the value
Expand Down Expand Up @@ -290,4 +301,4 @@ private static bool TryConvertEnumerable<T>(
return true;
}
}
}
}

0 comments on commit c14b82c

Please sign in to comment.