Rollback transaction when a panic happens in callback (#2093)

This commit is contained in:
ch3rub1m 2018-09-14 15:53:49 +08:00 committed by Jinzhu
parent 123d4f50ef
commit 5be9bd3413
1 changed files with 8 additions and 0 deletions

View File

@ -855,6 +855,14 @@ func (scope *Scope) inlineCondition(values ...interface{}) *Scope {
}
func (scope *Scope) callCallbacks(funcs []*func(s *Scope)) *Scope {
defer func() {
if err := recover(); err != nil {
if db, ok := scope.db.db.(sqlTx); ok {
db.Rollback()
}
panic(err)
}
}()
for _, f := range funcs {
(*f)(scope)
if scope.skipLeft {