signumsoftware / framework

Open Source framework for writing data-centric applications using the latest versions of .Net Core, C# (not-nullable), ASP.NET Web API, Typescript (strict), React, D3 and Sql Server or PostgreeSQL
https://www.signumsoftware.com/en/Framework
MIT License
221 stars 84 forks source link

Fix StackOverflow Exception while exporting Workflow asset #648

Open xickwy opened 1 month ago

xickwy commented 1 month ago

When you need to export a workflow with a script/lane as the same workflow, it enters in a loop exporting the same Entity and generate a Stack Overflow.

This verify if the subworkflow is the same as main and use the same Guid, and don't export the Entity with ctx.Include(a.SubWorkflow.Workflow).

To replicate this error, in a live environment. Create a new Workflow and put a Activity of type CallWorkflow and put the same workflow. In the script paste this (replacing your entity to test): return new List<EntityTestWorkflow> { new EntityTestWorkflow() };

Then save the workflow, And try to export. It give a loop exporting the same Activity every 5-10 stacks in the ToXml of WorkflowImportExport.

This fix the ToXml.

Now the opposite. If you try to import the asset, got the same loop and got a stackoverflow.

In FromXml check if the entity of the workflow is the same as the main entity (Using the Guid from the Xml). If it use the same, got the same main entity instead of enter the (WorkflowEntity)ctx.GetEntity((Guid)elem.Attribute("Workflow")

Tested and verified in a working test environment with the above test to replicate the error and a production server that we need to export a workflow with this type of Activity.

Pics from the test workflow image image