mirror of https://github.com/go-gorm/gorm.git
Rollback transaction when a panic happens in callback (#2093)
This commit is contained in:
parent
123d4f50ef
commit
5be9bd3413
8
scope.go
8
scope.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue