Respond with 500 in case of Incidents (#5004)

* Modify error handling in Workflow middleware

The handling for workflow faults in the Workflow Middleware has been altered. Previously, the code was checking if the workflow state status was designated as 'Faulted'. Now it checks if there are any incidents or problems in the workflow state, which provides a more comprehensive fault check.

* Prevent deletion of all records with empty conditions

Added checks in the 'Delete' and 'PagedDelete' methods in the 'Store.cs' file to prevent the deletion of all records if the conditions are empty. This will protect the system from unintentional data loss by stopping the execution of these methods when they have no parameters.
This commit is contained in:
Sipke Schoorstra 2024-02-28 09:46:24 +01:00 committed by GitHub
parent 66a620b7d9
commit ce27c9a279
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View file

@ -245,6 +245,11 @@ public class Store<T> where T : notnull
{
var query = _dbConnectionProvider.CreateQuery().Delete(TableName);
filter(query);
// If there are no conditions, we don't want to delete all records.
if (!query.Parameters.ParameterNames.Any())
return 0;
using var connection = _dbConnectionProvider.GetConnection();
return await query.ExecuteAsync(connection);
}
@ -262,6 +267,11 @@ public class Store<T> where T : notnull
{
var selectQuery = _dbConnectionProvider.CreateQuery().From(TableName, primaryKey);
filter(selectQuery);
// If there are no conditions, we don't want to delete all records.
if (!selectQuery.Parameters.ParameterNames.Any())
return 0;
selectQuery = selectQuery.OrderBy(orderFields.ToArray()).Page(pageArgs);
var deleteQuery = _dbConnectionProvider.CreateQuery().Delete(TableName, primaryKey, selectQuery);

View file

@ -174,7 +174,7 @@ public class WorkflowsMiddleware
cancellationTokens);
// Check if there were any errors.
var faultedWorkflowState = affectedWorkflowStates.FirstOrDefault(x => x.SubStatus == WorkflowSubStatus.Faulted);
var faultedWorkflowState = affectedWorkflowStates.FirstOrDefault(x => x.Incidents.Any());
if (faultedWorkflowState != null)
await HandleWorkflowFaultAsync(serviceProvider, httpContext, faultedWorkflowState, systemCancellationToken);
@ -291,9 +291,7 @@ public class WorkflowsMiddleware
private async Task<bool> HandleWorkflowFaultAsync(IServiceProvider serviceProvider, IWorkflowRuntime workflowRuntime, HttpContext httpContext, WorkflowExecutionResult workflowExecutionResult, CancellationToken cancellationToken)
{
var subStatus = workflowExecutionResult.SubStatus;
if (subStatus != WorkflowSubStatus.Faulted || httpContext.Response.HasStarted)
if (!workflowExecutionResult.Incidents.Any() || httpContext.Response.HasStarted)
return false;
var workflowState = (await workflowRuntime.ExportWorkflowStateAsync(workflowExecutionResult.WorkflowInstanceId, cancellationToken))!;