Skip to content

Commit

Permalink
better nil transaction checking for commits (#8787)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Jan 24, 2025
1 parent 25657eb commit f19ceef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
11 changes: 7 additions & 4 deletions go/libraries/doltcore/sqle/database_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,15 @@ func (p *DoltDatabaseProvider) CreateDatabase(ctx *sql.Context, name string) err
}

func commitTransaction(ctx *sql.Context, dSess *dsess.DoltSession, rsc *doltdb.ReplicationStatusController) error {
// there is no current transaction to commit; this happens in certain tests like
currentTx := ctx.GetTransaction()

err := dSess.CommitTransaction(ctx, currentTx)
if err != nil {
return err
if currentTx != nil {
err := dSess.CommitTransaction(ctx, currentTx)
if err != nil {
return err
}
}

newTx, err := dSess.StartTransaction(ctx, sql.ReadWrite)
if err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions go/libraries/doltcore/sqle/dsess/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,6 @@ func (d *DoltSession) CommitTransaction(ctx *sql.Context, tx sql.Transaction) (e
return nil
}

// There is no transaction to commit
if tx == nil {
return nil
}

dirties := d.dirtyWorkingSets()
if len(dirties) == 0 {
return nil
Expand Down
10 changes: 7 additions & 3 deletions go/libraries/doltcore/sqle/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ func ExecuteSql(dEnv *env.DoltEnv, root doltdb.RootValue, statements string) (do
}
}

err = dsess.DSessFromSess(ctx.Session).CommitTransaction(ctx, ctx.GetTransaction())
if err != nil {
return nil, err
// commit leftover transaction
trx := ctx.GetTransaction()
if trx != nil {
err = dsess.DSessFromSess(ctx.Session).CommitTransaction(ctx, trx)
if err != nil {
return nil, err
}
}

return db.GetRoot(ctx)
Expand Down

0 comments on commit f19ceef

Please sign in to comment.