fix: dont prematurely close transaction #140

Merged
tim merged 1 commits from fix-transaction into prod 2025-05-29 18:12:44 +00:00

View File

@@ -56,7 +56,9 @@ func (s TransactionImpl) Add(tx *sqlx.Tx, user *types.User, transactionInput typ
}
var err error
ownsTransaction := false
if tx == nil {
ownsTransaction = true
tx, err = s.db.Beginx()
err = db.TransformAndLogDbError("transaction Add", nil, err)
if err != nil {
@@ -104,10 +106,12 @@ func (s TransactionImpl) Add(tx *sqlx.Tx, user *types.User, transactionInput typ
}
}
err = tx.Commit()
err = db.TransformAndLogDbError("transaction Add", nil, err)
if err != nil {
return nil, err
if ownsTransaction {
err = tx.Commit()
err = db.TransformAndLogDbError("transaction Add", nil, err)
if err != nil {
return nil, err
}
}
return transaction, nil