elsa-core icon indicating copy to clipboard operation
elsa-core copied to clipboard

[BUG] Context.SetVariable not stored in WorkflowInstance

Open Sverre-W opened this issue 8 months ago • 2 comments

Description

When using the Context.SetVariable the variable is not stored after the workflow was suspended. The storage provider is the WorkflowStorageDriver.

Steps to Reproduce

Using the following snippet to reproduce


public class CreateVariableActivity : CodeActivity
{
    protected override void Execute(ActivityExecutionContext context)
    {
        var variable = context.SetVariable("Foo", "Bar");
        Console.Write(variable.StorageDriverType);
    }
}

public class ReadVariableActivity : CodeActivity<string>
{
    protected override void Execute(ActivityExecutionContext context)
    {
        var foo = context.GetVariable<string>("Foo");
        Result.Set(context, foo);
    }
}

class SampleWorkflow : WorkflowBase
{
    protected override void Build(IWorkflowBuilder workflow)
    {
        var variable1 = new Variable<string>();

        workflow.Root = new Sequence
        {
            Variables =
            {
                variable1
            },

            Activities =
            {
                new CreateVariableActivity(),
                new Delay(TimeSpan.FromSeconds(5)),
                new ReadVariableActivity
                {
                    Result = new(variable1)
                },
                new WriteLine(variable1)
            }
        };
    }
}

Expected Behavior

For the variable to return "Bar"

Actual Behavior

The variable is null

Screenshots

Variable Storage Provider

image

Variable is null

image

Sverre-W avatar Jun 24 '24 09:06 Sverre-W