Description

https://github.com/go-gorm/gorm/blob/6d64e31965f5c9c383e351683052d7aec68c56b5/finisher_api.go?#L522 In this line, savepoint name is generated from the pointer to the callback passed to the gorm.Transaction function.

If you ever reuse the callback, or the closure happens to be allocated at the same address, the transaction will silently fail.

Please allow to pass the savepoint name, or at least add some randomness there.

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: pitluga

This bit me as well. In order to work around it, I kept track of the nested depth of my transactions and uses a different copy of the function. If you do a switch statement, you can get different pointers for different nested depths. Something like:

var txfn func(tx *gorm.DB) error

switch depth {
case 0: 
  txfn = func(tx *gorm.DB) error { ... }
case 1: 
  txfn = func(tx *gorm.DB) error { ... }
case n: 
  txfn = func(tx *gorm.DB) error { ... }
default:
  return errors.New("too deep")
}

Comment From: phroggyy

Re-reported and reproduced in #7173, fix in #7174