go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
37.02k stars 3.94k forks source link

Generate unique savepoint names for nested transactions #7174

Closed phroggyy closed 2 months ago

phroggyy commented 2 months ago

What did this pull request do?

This test changes SAVEPOINT names from relying on the memory address of the callback (which can cause unexpected issues with partial rollbacks), to using a random integer.

The integer is generated using maphash.Hash, which is used as that internally relies on runtime.fastrand, which is the most performant way to get a random integer.

I've ensured the test fails without my code changes, and passes with them applied.

Use Case Description

Covered in https://github.com/go-gorm/gorm/issues/7173