From 3e2662582c2e5470148e8f294b925be6476fb019 Mon Sep 17 00:00:00 2001 From: John Guo Date: Wed, 19 May 2021 21:17:21 +0800 Subject: [PATCH] improve nested transaction feature for package gdb --- database/gdb/gdb_transaction.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/database/gdb/gdb_transaction.go b/database/gdb/gdb_transaction.go index 1973a4e57..187e9e9ea 100644 --- a/database/gdb/gdb_transaction.go +++ b/database/gdb/gdb_transaction.go @@ -150,6 +150,11 @@ func (tx *TX) transactionKey() string { // Note that, you should not Commit or Rollback the transaction in function `f` // as it is automatically handled by this function. func (tx *TX) Transaction(ctx context.Context, f func(ctx context.Context, tx *TX) error) (err error) { + // Check transaction object from context. + if TXFromCtx(ctx) == nil { + // Inject transaction object into context. + ctx = WithTX(ctx, tx) + } err = tx.Begin() if err != nil { return err