Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix casting during workflow instance restart #16139

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ protected virtual async Task<IContent> GetContentAsync(WorkflowExecutionContext
else
{
// If no expression was provided, see if the content item was provided as an input or as a property.
content = workflowContext.Input.GetValue<IContent>(ContentEventConstants.ContentItemInputKey)
?? workflowContext.Properties.GetValue<IContent>(ContentEventConstants.ContentItemInputKey);
content = workflowContext.Input.GetValue<ContentItem>(ContentEventConstants.ContentItemInputKey)
?? workflowContext.Properties.GetValue<ContentItem>(ContentEventConstants.ContentItemInputKey);
}

if (content != null && content.ContentItem.ContentItemId != null)
if (content?.ContentItem?.ContentItemId != null)
{
return content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async override Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecuti
}
else
{
contentItem = workflowContext.Input.GetValue<IContent>(ContentEventConstants.ContentItemInputKey)?.ContentItem;
contentItem = workflowContext.Input.GetValue<ContentItem>(ContentEventConstants.ContentItemInputKey)?.ContentItem;
}

if (contentItem == null)
Expand Down Expand Up @@ -155,7 +155,7 @@ public async override Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecuti
{
workflowContext.CorrelationId = contentItem.ContentItemId;
}

workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;
workflowContext.LastResult = contentItem;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text.Json;

namespace OrchardCore.Workflows.Helpers
{
Expand All @@ -19,12 +20,19 @@ public static TValue GetValue<TValue>(this IDictionary<string, object> dictionar
{
var value = dictionary.GetValue(key);

if (value != null)
if (value == null)
{
return (TValue)value;
return default;
}

return default;
if (value is not TValue castedValued)
{
var json = JConvert.SerializeObject(value);

return JConvert.DeserializeObject<TValue>(json);
}

return castedValued;
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down