From 9899989eceb581de42d1eb1a746da82eb1777e7d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 6 Jan 2025 10:21:14 -0800 Subject: [PATCH] Add missing transaction when set merge (#33113) backport from #33079 `SetMerged` should be in a database transaction otherwise it's possible to have dirty data. --- services/pull/check.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/pull/check.go b/services/pull/check.go index 736be4611b..baca1511a2 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -301,11 +301,16 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool { pr.Merger = merger pr.MergerID = merger.ID - if merged, err := pr.SetMerged(ctx); err != nil { + if err := db.WithTx(ctx, func(ctx context.Context) error { + if merged, err := pr.SetMerged(ctx); err != nil { + return err + } else if !merged { + return errors.New("setMerged failed") + } + return nil + }); err != nil { log.Error("%-v setMerged : %v", pr, err) return false - } else if !merged { - return false } notify_service.MergePullRequest(ctx, merger, pr)