From 3541575a75f7558570d2e1622845623efb360a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 26 May 2025 17:57:48 +0200 Subject: [PATCH] Avoid error when fetching task that was assigned to soft-deleted worker When a Worker is soft-deleted, references to it are not cleaned up by the database (that only happens when it is really deleted). As a result, the "last-assigned worker of a task" field is still set, but the worker itself cannot be fetched any more. This is just a quick fix to avoid an error. It's probably better to remove the soft-deletion of Workers, as the feature is not really used anyway. Or to implement it properly, so that the info is used. --- internal/manager/api_impl/jobs_query.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/manager/api_impl/jobs_query.go b/internal/manager/api_impl/jobs_query.go index f72da691..1979b89f 100644 --- a/internal/manager/api_impl/jobs_query.go +++ b/internal/manager/api_impl/jobs_query.go @@ -143,11 +143,16 @@ func (f *Flamenco) FetchTask(e echo.Context, taskID string) error { // worker's UUID and let the caller fetch the worker info themselves if // necessary. taskWorker, err := f.persist.FetchWorker(ctx, taskJobWorker.WorkerUUID) - if err != nil { - logger.Warn().Err(err).Msg("error fetching task worker") + switch { + case errors.Is(err, persistence.ErrWorkerNotFound): + // This is fine, workers can be soft-deleted from the database, and then + // the above FetchWorker call will not return it. + case err != nil: + logger.Warn().Err(err).Str("worker", taskJobWorker.WorkerUUID).Msg("error fetching task worker") return sendAPIError(e, http.StatusInternalServerError, "error fetching task worker") + default: + apiTask.Worker = workerToTaskWorker(taskWorker) } - apiTask.Worker = workerToTaskWorker(taskWorker) } // Fetch & convert the failure list.