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

Fix error when including Fallbacks on non-Simple backend #260

Merged

Conversation

arthurnn
Copy link
Contributor

Commit 12aa0f0 introduced a bug, where
if Fallbacks module is included in a class that doesnt define
translations the code would fail. This is a pretty common
scenario, for instance when the backend is a Chain. Also this was
pretty common case to fail in rails, as its include Fallbacks in the
I18n.backend, like this:

I18n.backend.class.send(:include, I18n::Backend::Fallbacks)

This stops using the translations method in the fallbacks, and instead
ignores I18n::InvalidLocale errors.

[fixes #238]
[fixes #258]
[fixes #259]

review @carlosantoniodasilva

Commit 12aa0f0 introduced a bug, where
if `Fallbacks` module is included in a class that doesnt define
`translations` the code would fail. This is a pretty common
scenario, for instance when the backend is a `Chain`. Also this was
pretty common case to fail in rails, as its include Fallbacks in the
I18n.backend, like this:
```
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
```

This stops using the `translations` method in the fallbacks, and instead
ignores `I18n::InvalidLocale` errors.

[fixes ruby-i18n#238]
[fixes ruby-i18n#258]
[fixes ruby-i18n#259]
@thedarkone
Copy link
Contributor

Just a note: I vaguely remember that when I investigated this in my "optimized" fork (#138) I found out that fallbacks usually generate a bazillion of fallback locales that usually do not exist thus resulting in a series of I18n::InvalidLocales exceptions for no good reason (exceptions are kinda slow). Therefore I ended up replacing rescue I18n::InvalidLocale with explicit key checks (rescue I18n::InvalidLocale was my initial fix as well).

@stuarthannig
Copy link

WE NEED THIS TO GO IN ASAP!

0.6.10 hosed our Production environment and took hours to figure out. Rolled back to 0.6.9 and all working again. MAJOR BUG for 0.6.10 that will hose a lot of the Rails ecosystem!

@carlosantoniodasilva
Copy link
Member

@stuarthannig I'm sorry about that, unfortunately our tests didn't catch the problem before. 0.6.10 has been yanked for now, expect a new release soon including this fix. Thanks.

I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, backend)
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we having two fallbacks being triggered now? One being included in Chain, other in the Backend class being used here. Does this affect anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, it would call fallback 2x. But I am sure this is not an issue. I wanted to add the send(:include, I18n::Backend::Fallbacks) to the root backend because thats what rails does.
I probably could refactor those tests, to simulate situations similar to the ones that happen on rails code.

carlosantoniodasilva added a commit that referenced this pull request May 31, 2014
Fix error when including Fallbacks on non-Simple backend
@carlosantoniodasilva carlosantoniodasilva merged commit 1e983c0 into ruby-i18n:master May 31, 2014
@carlosantoniodasilva
Copy link
Member

@thedarkone thanks for sharing your thoughts/concerns on this one, I'm going to review your perf changes when I find some time here so we can get them in.

Thanks everyone.

@johnnyshields
Copy link

Not to throw rocks here but @stuarthannig is right that this faulty release / version yank was entirely avoidable. I flagged this issue originally on Jan 7 (#238), and I asked for attention multiple times but was ignored.

@carlosantoniodasilva
Copy link
Member

It was the first thing we could think of to avoid more people having issues installing it. I didn't want to release a possible-another version with problems without someone being able to verify it was working, so I did what I thought would be safer. I'm sorry I missed your issue before, I wasn't in the project when you sent it, anyway I'll try to review more carefully the issues before releasing. Thanks.

@carlosantoniodasilva
Copy link
Member

Btw I'm planning to release a new version with that fix soon, I'll keep you guys posted.

@johnnyshields
Copy link

@carlosantoniodasilva thanks for the quick response. Gem yank was the appropriate action when the issue was noticed. Appreciate all your great work on this and Rails.

@arthurnn arthurnn deleted the fix_fallback_ensure_locale branch June 10, 2014 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants