mirror of
https://github.com/dolthub/dolt.git
synced 2025-12-21 11:59:41 -06:00
panic fix for 0 rows resolved (#1471)
* fix panic that occurs when a delete query against a conflict table affects 0 rows * bats test for 0 conflict delete * formatting * fixes
This commit is contained in:
@@ -42,6 +42,7 @@ const (
|
||||
|
||||
var tableNameRegex, _ = regexp.Compile(TableNameRegexStr)
|
||||
|
||||
var ErrNoConflictsResolved = errors.New("no conflicts resolved")
|
||||
var ErrNoAutoIncrementValue = fmt.Errorf("auto increment set for non-numeric column type")
|
||||
|
||||
// IsValidTableName returns true if the name matches the regular expression TableNameRegexStr.
|
||||
@@ -398,7 +399,7 @@ func (t *Table) ResolveConflicts(ctx context.Context, pkTuples []types.Value) (i
|
||||
}
|
||||
|
||||
if removed == 0 {
|
||||
return invalid, notFound, tbl, nil
|
||||
return invalid, notFound, tbl, ErrNoConflictsResolved
|
||||
}
|
||||
|
||||
conflicts, err := confEdit.Map(ctx)
|
||||
|
||||
@@ -15,6 +15,8 @@ package dtables
|
||||
// limitations under the License.
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
@@ -159,6 +161,10 @@ func (cd *conflictDeleter) Close(ctx *sql.Context) error {
|
||||
_, _, updatedTbl, err := cd.ct.tbl.ResolveConflicts(ctx, cd.pks)
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, doltdb.ErrNoConflictsResolved) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -926,7 +926,7 @@ SQL
|
||||
# Test resolve nonexistant key
|
||||
run dolt conflicts resolve foo 999
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "not the primary key of a conflicting row" ]] || false
|
||||
[[ "$output" =~ "no conflicts resolved" ]] || false
|
||||
|
||||
dolt conflicts resolve --theirs foo
|
||||
run dolt sql -q 'select count(*) from foo'
|
||||
|
||||
@@ -78,6 +78,12 @@ teardown() {
|
||||
run dolt sql -r csv -q "SELECT * FROM dolt_conflicts"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "$EXPECTED" ]] || false
|
||||
|
||||
# delete an already resolved conflict a 2nd time should not cause problems
|
||||
run dolt sql -q "DELETE from dolt_conflicts_one_pk WHERE our_pk1 = 0"
|
||||
[ "$status" -eq 0 ]
|
||||
echo $output
|
||||
[[ "$output" =~ "Query OK, 0 rows affected" ]] || false
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user