Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Yoshi-Exeler opened this issue Feb 12, 2025 · 0 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@Yoshi-Exeler
Copy link

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.

@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

2 participants