From d9671bd565372103e8f787ea1a7b4d4c9c22263a Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Fri, 20 Jan 2023 14:52:24 -0800 Subject: [PATCH] go/libraries/doltcore/sqle/dsess: transactions.go: When merging working sets on call dolt_commit, ensure new commit also gets the merged commit root value. --- go/libraries/doltcore/sqle/dsess/transactions.go | 3 +++ .../sqle/enginetest/dolt_transaction_commit_test.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/go/libraries/doltcore/sqle/dsess/transactions.go b/go/libraries/doltcore/sqle/dsess/transactions.go index ea457d360d..5ce4fed8a0 100644 --- a/go/libraries/doltcore/sqle/dsess/transactions.go +++ b/go/libraries/doltcore/sqle/dsess/transactions.go @@ -232,6 +232,9 @@ func (tx *DoltTransaction) doCommit( } var newCommit *doltdb.Commit + if commit != nil { + commit.Roots.Staged = mergedWorkingSet.WorkingRoot() + } mergedWorkingSet, newCommit, err = writeFn(ctx, tx, commit, mergedWorkingSet, existingWSHash) if err == datas.ErrOptimisticLockFailed { // this is effectively a `continue` in the loop diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_transaction_commit_test.go b/go/libraries/doltcore/sqle/enginetest/dolt_transaction_commit_test.go index cec21ecd95..5782956058 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_transaction_commit_test.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_transaction_commit_test.go @@ -272,6 +272,13 @@ func TestDoltTransactionCommitTwoClients(t *testing.T) { Query: "/* client c */ SELECT * FROM x ORDER BY y;", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, + // After we commit both of these transactions, our working set should not have any pending changes. + // In the past, we have merged the working set but failed to land the merged root value in the + // commit itself. + { + Query: "/* client c */ SELECT COUNT(*) FROM DOLT_DIFF('HEAD', 'WORKING', 'x');", + Expected: []sql.Row{{0}}, + }, }, }) _, err := harness.NewEngine(t)