Preserve I18n.locale set when after_commit is called #36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This gem is commonly used to wrap ActiveJobs, see e.g. #19 and #27. ActiveJob preserves the locale set when the job is created: ActiveJob guide. after_commit everywhere currently does not preserve the locale, meaning that wrapping an ActiveJob with
after_commit
as shown in the linked issues will lose the locale information.We encountered this as a problem because we use
after_commit
for ActionMailer'sdeliver_later
(which uses ActiveJob to preserve the locale, as shown in the linked guide). I wrote a monkeypatch to preserve the locale in AfterCommitEverywhere to work around this. Since it's quite common to use this gem to wrap ActiveJobs, I figured I'd PR the monkeypatch as a proper change here, now that we've been successfully running it in production for a bit. Maybe it can be useful to more users of this gem.