Rollback transaction when a panic happens in callback

This commit is contained in:
ch3rub1m 2018-09-14 15:39:14 +08:00
parent 123d4f50ef
commit 743efe0d69

View File

@ -855,6 +855,14 @@ func (scope *Scope) inlineCondition(values ...interface{}) *Scope {
} }
func (scope *Scope) callCallbacks(funcs []*func(s *Scope)) *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 { for _, f := range funcs {
(*f)(scope) (*f)(scope)
if scope.skipLeft { if scope.skipLeft {