From ef991ae0c0e140f02d8ad23dcecf8f9a6524875b Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Fri, 11 Mar 2022 14:40:55 +0800 Subject: [PATCH] add transaction for artifact delete (#16506) Add transaction for artifact deletion, given API has the transaction when to call artifact controller but other object may not, for example jobservice job. Here, force add the tx to ensure all the things can be rolled back. Signed-off-by: Wang Yan --- src/controller/artifact/controller.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controller/artifact/controller.go b/src/controller/artifact/controller.go index cb5eddf68..b10c57a3d 100644 --- a/src/controller/artifact/controller.go +++ b/src/controller/artifact/controller.go @@ -311,7 +311,9 @@ func (c *controller) Delete(ctx context.Context, id int64) error { if err != nil { return err } - return c.deleteDeeply(ctx, id, true, len(accs) > 0) + return orm.WithTransaction(func(ctx context.Context) error { + return c.deleteDeeply(ctx, id, true, len(accs) > 0) + })(orm.SetTransactionOpNameToContext(ctx, "tx-delete-artifact-delete")) } // "isRoot" is used to specify whether the artifact is the root parent artifact