Bug - Accessing Output via Liquid (#2509)

* do not create a new Scope - reuse workflowExecutionContext's scope

* Upgrade Rebus.ServiceProvider to 7.0

* using the correct storage provider

Co-authored-by: Martin <mp@prakom.net>
This commit is contained in:
noxe 2021-11-24 11:52:46 +01:00 committed by GitHub
parent 3f327ef742
commit 5fae56d2bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ using Elsa.Providers.WorkflowStorage;
using Elsa.Scripting.Liquid.Helpers;
using Elsa.Scripting.Liquid.Messages;
using Elsa.Scripting.Liquid.Options;
using Elsa.Services;
using Elsa.Services.Models;
using Elsa.Services.WorkflowStorage;
using Fluid;
@ -26,12 +27,14 @@ namespace Elsa.Scripting.Liquid.Handlers
private readonly IConfiguration _configuration;
private readonly IWorkflowStorageService _workflowStorageService;
private readonly LiquidOptions _liquidOptions;
private readonly IActivityTypeService _activityTypeService;
public ConfigureLiquidEngine(IConfiguration configuration, IWorkflowStorageService workflowStorageService, IOptions<LiquidOptions> liquidOptions)
public ConfigureLiquidEngine(IConfiguration configuration, IWorkflowStorageService workflowStorageService, IOptions<LiquidOptions> liquidOptions, IActivityTypeService activityTypeService)
{
_configuration = configuration;
_workflowStorageService = workflowStorageService;
_liquidOptions = liquidOptions.Value;
_activityTypeService = activityTypeService;
}
public Task Handle(EvaluatingLiquidExpression notification, CancellationToken cancellationToken)
@ -61,7 +64,7 @@ namespace Elsa.Scripting.Liquid.Handlers
memberAccessStrategy.Register<ActivityExecutionContext, LiquidActivityModel>((x, a) => GetActivityModel(x, a));
memberAccessStrategy.Register<LiquidActivityModel, object?>((model, name) => GetActivityProperty(model, name, cancellationToken));
memberAccessStrategy.Register<LiquidObjectAccessor<JObject>, JObject>((x, name) => x.GetValueAsync(name));
memberAccessStrategy.Register<ExpandoObject, object>((x, name) => ((IDictionary<string, object>) x)[name]);
memberAccessStrategy.Register<ExpandoObject, object>((x, name) => ((IDictionary<string, object>)x)[name]);
memberAccessStrategy.Register<JObject, object?>((source, name) => source.GetValue(name, StringComparison.OrdinalIgnoreCase));
if (_liquidOptions.EnableConfigurationAccess)
@ -94,7 +97,14 @@ namespace Elsa.Scripting.Liquid.Handlers
var workflowExecutionContext = activityExecutionContext.WorkflowExecutionContext;
var activityBlueprint = activityModel.ActivityId != null ? workflowExecutionContext.GetActivityBlueprintById(activityModel.ActivityId)! : workflowExecutionContext.GetActivityBlueprintByName(activityModel.ActivityName!)!;
var activityId = activityBlueprint.Id;
var storageProviderName = activityBlueprint.PropertyStorageProviders.GetItem(name);
var activityType = await _activityTypeService.GetActivityTypeAsync(activityBlueprint.Type, cancellationToken);
var activityDescriptor = await _activityTypeService.DescribeActivityType(activityType, cancellationToken);
var property = activityDescriptor.OutputProperties.FirstOrDefault(d => d.Name == name);
var storageProviderName = activityBlueprint.PropertyStorageProviders.GetItem(name) ?? property?.DefaultWorkflowStorageProvider;
var storageContext = new WorkflowStorageContext(workflowExecutionContext.WorkflowInstance, activityId);
var value = await _workflowStorageService.LoadAsync(storageProviderName, storageContext, name, cancellationToken);
return value;