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

calling methods that trigger callbacks can cause after_commit callbacks to run multiple times #29

Open
DeedleFake opened this issue Nov 7, 2023 · 1 comment

Comments

@DeedleFake
Copy link

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,

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.

@Envek
Copy link
Owner

Envek commented Dec 1, 2023

That's weird, but it is hard to understand how to replicate such a behavior.

Can you please create a reproduction example of your use case, e.g. using ActiveRecord's executable test case template?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants