Skip to content

Commit 1cc05a8

Browse files
elliotguntonJoibel
authored andcommitted
fix!: return latest workflow for retried-persisted workflows (#15030)
(cherry picked from commit e98b6b3) Signed-off-by: Elliot Gunton <[email protected]> Signed-off-by: Alan Clucas <[email protected]>
1 parent 96335d4 commit 1cc05a8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

persist/sqldb/workflow_archive.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ func phaseEqual(phase string) db.Cond {
360360
}
361361

362362
func (r *workflowArchive) GetWorkflow(uid string, namespace string, name string) (*wfv1.Workflow, error) {
363+
logger := logging.RequireLoggerFromContext(ctx)
363364
var err error
364365
archivedWf := &archivedWorkflowRecord{}
365366
if uid != "" {
@@ -384,14 +385,19 @@ func (r *workflowArchive) GetWorkflow(uid string, namespace string, name string)
384385
}
385386
num := int64(total.Total)
386387
if num > 1 {
387-
return nil, fmt.Errorf("found %d archived workflows with namespace/name: %s/%s", num, namespace, name)
388+
logger.WithFields(logging.Fields{
389+
"namespace": namespace,
390+
"name": name,
391+
"num": num,
392+
}).Debug(ctx, "returning latest of archived workflows")
388393
}
389394
err = r.session.SQL().
390395
Select("workflow").
391396
From(archiveTableName).
392397
Where(r.clusterManagedNamespaceAndInstanceID()).
393398
And(namespaceEqual(namespace)).
394399
And(nameEqual(name)).
400+
OrderBy("-startedat").
395401
One(archivedWf)
396402
} else {
397403
return nil, sutils.ToStatusError(fmt.Errorf("both name and namespace are required if uid is not specified"), codes.InvalidArgument)

0 commit comments

Comments
 (0)