Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: fix a bug introduced in c94c3ea0e1c4e7a34d40e93746ef6624ff9e56d8 [formerly 72adb8428e03ab029699c029241a47ff144f7590] [formerly 710fd5fe54605aef19eba654958452206a59ea1b [formerly b10cb511f4758c592936c8817b66f29f8b14ac99]] (#319)

spinningbot89f0e8df089e
diff --git a/store/task.go b/store/task.go
index 6bbfb3714e..3d1ee1f5ea 100644
--- a/store/task.go
+++ b/store/task.go
@@ -407,19 +407,12 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Ta
}
taskRun, err := s.TaskRunService.FindTaskRunTx(ctx, tx.Tx, taskRunFind)
if err != nil {
- if common.ErrorCode(err) == common.NotFound {
- } else {
- return nil, err
- }
- }
- if taskRun == nil && patch.Status != api.TaskRunning {
- return nil, fmt.Errorf("no applicable running task to change status")
- }
- if patch.Status == api.TaskRunning {
- return nil, fmt.Errorf("task is already running: %v", task.Name)
+ return nil, err
}
-
- if patch.Status == api.TaskRunning {
+ if taskRun == nil {
+ if patch.Status != api.TaskRunning {
+ return nil, fmt.Errorf("no applicable running task to change status")
+ }
taskRunCreate := &api.TaskRunCreate{
CreatorID: patch.UpdaterID,
TaskID: task.ID,
@@ -431,6 +424,9 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Ta
return nil, err
}
} else {
+ if patch.Status == api.TaskRunning {
+ return nil, fmt.Errorf("task is already running: %v", task.Name)
+ }
taskRunStatusPatch := &api.TaskRunStatusPatch{
ID: &taskRun.ID,
UpdaterID: patch.UpdaterID,