# HG changeset patch # User Tom Gottfried # Date 1582712728 -3600 # Node ID 5c43427fc2bf03464f5c8be64b31000632279e6c # Parent 331a59ebaf548856121f92e1f0bc4874f3d311b7 Do not rollback savepoint if statement returned no rows Statements that might or might not return rows can modify the database in both cases e.g. through DML in functions, CTEs or triggers. Not returning any rows but modifying the database is not an error in such a case. Thus, prevent ROLLBACK. diff -r 331a59ebaf54 -r 5c43427fc2bf pkg/imports/misc.go --- a/pkg/imports/misc.go Tue Feb 25 15:20:42 2020 +0100 +++ b/pkg/imports/misc.go Wed Feb 26 11:25:28 2020 +0100 @@ -37,7 +37,7 @@ // of managing database SAVEPOINTs. // If the returned function is called with a callback // the callback is run in a SAVEPOINT. -// If the callback returns w/o an error the SAVEPOINT +// If the callback returns w/o an error or with sql.ErrNoRows the SAVEPOINT // is released. Otherwise the SAVEPOINT is rolled back. func Savepoint( ctx context.Context, @@ -64,9 +64,13 @@ } } }() - if err = fn(); err == nil { + + // Release SAVEPOINT if statements run in fn returned no database error + if err = fn(); err == nil || err == sql.ErrNoRows { done = true - _, err = tx.ExecContext(ctx, release) + if _, err2 := tx.ExecContext(ctx, release); err2 != nil { + err = err2 + } } return }