Envek / Envek/after_commit_everywhere
calling methods that trigger callbacks can cause `after_commit` callbacks to run multiple times
Open
- Dominant language
- Ruby
- Stars
- 789
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
If an `after_commit` is called inside of a transaction and that transaction has calls to model methods that can trigger model callbacks, the block passed to `after_commit` will be called multiple times. For example,
```ruby
ActiveRecord::Base.transaction do
User.create!(email:)
ev = Event.create!(name: 'created user', source: 'admin')
after_commit do
send_welcome_email!
end
track_event!(ev)
end
```
When this transaction runs, the welcome e-mail will be sent multiple times because the block is run repeatedly.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.