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

Rails app crashes when a null locale is present #59

Closed
sajoku opened this issue Mar 2, 2015 · 5 comments
Closed

Rails app crashes when a null locale is present #59

sajoku opened this issue Mar 2, 2015 · 5 comments

Comments

@sajoku
Copy link

sajoku commented Mar 2, 2015

Today I was investigating a startup failure in a Rails app with the following error:

/Users/sajoku/.rvm/gems/ruby-2.2.0/bundler/gems/i18n-active_record-2d9a22b6a4e5/lib/i18n/backend/active_record/translation.rb:76:in `block in available_locales': undefined method `to_sym' for nil:NilClass (NoMethodError)
        from /Users/sajoku/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:46:in `map'

After some investigation the error led me (and my pair buddy) to the translations table in the database and check all the translations. The last two entries had NULL as :locale. Removing this fixed the startup issue.

I'm not sure if my "fix" is desirable but wanna check this out and let me know what you think?
sajoku@2f563cd
The reason I'm not sure is because this seems to be something the user could simply fix by making sure locale has a default value or can't be NULL in the database. What are your thought on this?

Or maybe let the user know in te README (or wiki perhaps?)?
sajoku@b284fee

@sajoku
Copy link
Author

sajoku commented Mar 3, 2015

@CDingerdis This is the issue we ran in to. Wanna check out the proposed solution?

@rvfx
Copy link

rvfx commented May 15, 2016

Thank you, this information helped me alot!

sajoku referenced this issue in sajoku/i18n-active_record Aug 17, 2016
* Checking for this NULL value because the Rails (clients) app crashes
with the following message:
/Users/sajoku/.rvm/gems/ruby-2.2.0/bundler/gems/i18n-active_record-2d9a2
2b6a4e5/lib/i18n/backend/active_record/translation.rb:76:in `block in
available_locales': undefined method `to_sym' for nil:NilClass
(NoMethodError)
        from
/Users/sajoku/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_re
cord/relation/delegation.rb:46
@sajoku
Copy link
Author

sajoku commented Aug 17, 2016

@rvfx Awesome 😄

I haven't tested this with anything other than MySQL though, so be careful just implementing this with anything other than that.

@timfjord
Copy link
Collaborator

Hey @sajoku
Why don't you submit a PR with your fix.
I think IS NOT NULL is ok for all major sql adapters that we support

@sajoku
Copy link
Author

sajoku commented Nov 28, 2018

A bit late but I'll close this issue as I believe this is a non-issue for other people.

@sajoku sajoku closed this as completed Nov 28, 2018
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

3 participants