Preserve I18n.locale set when after_commit is called#36
Merged
Envek merged 2 commits intoEnvek:masterfrom Feb 7, 2025
Bilka2:preserve-locale
Merged
Preserve I18n.locale set when after_commit is called#36Envek merged 2 commits intoEnvek:masterfrom Bilka2:preserve-locale
Envek merged 2 commits intoEnvek:masterfrom
Bilka2:preserve-locale
Conversation
Owner
|
Thank you for your contribution! Released in 1.6.0 |
Contributor
Author
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_commitas shown in the linked issues will lose the locale information.We encountered this as a problem because we use
after_commitfor 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.