elsa-workflows / elsa-workflows/elsa-core

[BUG] Flowchart variables are not serialized by FlowchartJsonConverter

Open
#5,532 1 comment 0 reactions 0 assignees View on GitHub
bug triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

## Description
When adding workflow to a `WorkflowDefinitionStore` using `DefaultWorkflowDefinitionStorePopulator`, flowchart variables are not serialized. This of course results in the workflow not executing properly

## Steps to Reproduce
This issue can be reproduced by running this code snippet. Notice that there is a variable called `TextVar` specified, which is used by the `WriteLine` activity.
```
Workflow testWorkflow = new Workflow()
{
Id = "abc123",
Identity = new WorkflowIdentity(
DefinitionId: "123abc",
Version: 1,
Id: "abc123"
),
WorkflowMetadata = new WorkflowMetadata(
Name: "TestWorkflow",
ToolVersion: new Version(3, 0) // This, oddly, is required to use the activity name when getting results via javascript (getResultFromRunScript())
),
Root = new Flowchart()
{
Id = "flowchart",
Variables = new List() {
new Variable("TextVar", "This is the text to write")
},
Activities = new List() {
new WriteLine(new Input(new Expression("JavaScript", "getVariable('TextVar')")))
{
Id = "writeLine",
Name = "WriteLine",
CanStartWorkflow = true,
},
},
Connections = new List()
}
};

// save the workflow
IWorkflowDefinitionStorePopulator workflowDefinitionStorePopulator = scope.ServiceProvider.GetRequiredService();
await workflowDefinitionStorePopulator.AddAsync(new MaterializedWorkflow(testWorkflow, "RapidResponse", JsonWorkflowMaterializer.MaterializerName));

// run the workflow
IWorkflowDispatcher dispatcher = scope.ServiceProvider.GetRequiredService();
DispatchWorkflowResponse dispatchWorkflowResponse = await dispatcher.DispatchAsync(new Elsa.Workflows.Runtime.Requests.DispatchWorkflowDefinitionRequest()
{
DefinitionId = "123abc",
});

```

This is the serialized flowchart - notice that the `TestVar` variable is not present in the resultant JSON
```
{
"type": "Elsa.Flowchart",
"version": 1,
"id": "flowchart",
"nodeId": "abc123:flowchart",
"metadata": {},
"customProperties": {
"source": "FlowchartTest.cs:126"
},
"activities": [
{
"text": {
"typeName": "String",
"expression": {
"type": "JavaScript",
"value": "getVariable('TextVar')"
}
},
"id": "writeLine",
"nodeId": "abc123:flowchart:writeLine",
"name": "WriteLine",
"type": "Elsa.WriteLine",
"version": 1,
"customProperties": {
"source": "FlowchartTest.cs:131",
"canStartWorkflow": true
},
"metadata": {}
}
],
"connections": []
}
```

Of course this result in the workflow not executing properly. When the `WriteLine` activity is executed, the `Text` property is null.

## Expected Behavior
My expectation is that variables assigned to a flowchart are persisted in the serialized JSON and are available when the workflow is executed.

## Actual Behavior
Variables assigned to a Flowchart are not serialized.

## Troubleshooting Attempts
When debugging this issue, I noticed that in fact variables are not being serialized by `FlowchartJsonConverter`. Adding serialization/deserialization for variables appears to resolve the issue.

## Environment
Elsa 3.1.3, .Net 8

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.