diff --git a/pkg/manager/impl/execution_manager.go b/pkg/manager/impl/execution_manager.go index 4f4689715..bf926319c 100644 --- a/pkg/manager/impl/execution_manager.go +++ b/pkg/manager/impl/execution_manager.go @@ -1544,8 +1544,9 @@ func (m *ExecutionManager) TerminateExecution( logger.Infof(ctx, "couldn't find execution [%+v] to save termination cause", request.Id) return nil, err } + if common.IsExecutionTerminal(core.WorkflowExecution_Phase(core.WorkflowExecution_Phase_value[executionModel.Phase])) { - return nil, errors.NewFlyteAdminError(codes.PermissionDenied, "Cannot abort an already terminate workflow execution") + return nil, errors.NewAlreadyInTerminalStateError(ctx, "Cannot abort an already terminate workflow execution", executionModel.Phase) } err = transformers.SetExecutionAborting(&executionModel, request.Cause, getUser(ctx)) @@ -1553,6 +1554,7 @@ func (m *ExecutionManager) TerminateExecution( logger.Debugf(ctx, "failed to add abort metadata for execution [%+v] with err: %v", request.Id, err) return nil, err } + err = m.db.ExecutionRepo().Update(ctx, executionModel) if err != nil { logger.Debugf(ctx, "failed to save abort cause for terminated execution: %+v with err: %v", request.Id, err) diff --git a/pkg/manager/impl/execution_manager_test.go b/pkg/manager/impl/execution_manager_test.go index e8d16d348..a3c384312 100644 --- a/pkg/manager/impl/execution_manager_test.go +++ b/pkg/manager/impl/execution_manager_test.go @@ -3231,7 +3231,7 @@ func TestTerminateExecution_AlreadyTerminated(t *testing.T) { assert.Nil(t, resp) s, ok := status.FromError(err) assert.True(t, ok) - assert.Equal(t, codes.PermissionDenied, s.Code()) + assert.Equal(t, codes.FailedPrecondition, s.Code()) } func TestGetExecutionData(t *testing.T) {