Skip to content

Callbacks registered with the callback manager after the gorm:commit_or_rollback_transaction callback do not actually run after the transaction commits #7367

@Yoshi-Exeler

Description

@Yoshi-Exeler

GORM Playground Link

go-gorm/playground#789

Description

Callbacks registered with the callback manager after the gorm:commit_or_rollback_transaction callback do not actually run after the transaction commits. When using explicit transactions, execution of the gorm:commit_or_rollback_transaction hook should be delayed until the transaction actually commits.

My organizations use case for this behavior is to re-build an in-memory cache every time a record in a certain database table is modified. Since we recently started using explicit transactions with higher isolation levels, we have been experiencing lots of cache misses that are caused by the callback firing too early. At the time the callback fires, the records being affected by the transaction do not exist yet in the database even though we registered the callback to run after the transaction commits.

If registering a hook after a transaction commits is not the intended use case of db.Callbacks().After("gorm:commit_or_rollback_transaction").Register(hook,name) then i propose that such a hook should be added, because otherwise there is no way to react to the successful creation/deletion/modification of an entity while using explicit transactions.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions