diff --git a/go/libraries/doltcore/sqle/database_provider.go b/go/libraries/doltcore/sqle/database_provider.go index bda772aad43..2b6b84b96e8 100644 --- a/go/libraries/doltcore/sqle/database_provider.go +++ b/go/libraries/doltcore/sqle/database_provider.go @@ -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 diff --git a/go/libraries/doltcore/sqle/dsess/session.go b/go/libraries/doltcore/sqle/dsess/session.go index 8bcd5cf79e0..cce58943e78 100644 --- a/go/libraries/doltcore/sqle/dsess/session.go +++ b/go/libraries/doltcore/sqle/dsess/session.go @@ -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 diff --git a/go/libraries/doltcore/sqle/testutil.go b/go/libraries/doltcore/sqle/testutil.go index 9af4a26bcba..ee4ad010714 100644 --- a/go/libraries/doltcore/sqle/testutil.go +++ b/go/libraries/doltcore/sqle/testutil.go @@ -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)