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 {
|
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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user