Do not panic if Begin().Error was ignored (#1830) (#1881)

This commit is contained in:
lrita 2018-05-12 14:28:15 +08:00 committed by Jinzhu
parent 9044197ef9
commit a58b98acee
1 changed files with 2 additions and 1 deletions

View File

@ -504,7 +504,8 @@ func (s *DB) Commit() *DB {
// Rollback rollback a transaction // Rollback rollback a transaction
func (s *DB) Rollback() *DB { func (s *DB) Rollback() *DB {
if db, ok := s.db.(sqlTx); ok && db != nil { var emptySQLTx *sql.Tx
if db, ok := s.db.(sqlTx); ok && db != nil && db != emptySQLTx {
s.AddError(db.Rollback()) s.AddError(db.Rollback())
} else { } else {
s.AddError(ErrInvalidTransaction) s.AddError(ErrInvalidTransaction)