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

Faker translations missing when seeding data #285

Closed
ggrillone opened this issue Dec 6, 2014 · 6 comments
Closed

Faker translations missing when seeding data #285

ggrillone opened this issue Dec 6, 2014 · 6 comments

Comments

@ggrillone
Copy link

Rails version: 4.1.7
Ruby version: 2.1.4
Faker version: 1.4.3

I am attempting to use Faker to generate seed data, which keeps failing.

At first I was seeing the following error: NameError: uninitialized constant Faker

So I added a require 'faker' to the top of my seeds.rb file which resolved that issue.

However it doesn't seem to be able to find any of the translations:

rake aborted! I18n::MissingTranslationData: translation missing: en.faker.lorem.words

Everything works fine in my RSpec tests with Faker, just when it comes to seeding data there seems to be issues.

Here is the stack trace:

** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
rake aborted!
I18n::MissingTranslationData: translation missing: en.faker.lorem.words
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/i18n-0.6.11/lib/i18n.rb:314:in `handle_exception'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/i18n-0.6.11/lib/i18n.rb:160:in `translate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker.rb:128:in `rescue in translate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker.rb:120:in `translate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:12:in `words'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:30:in `sentence'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:36:in `block (2 levels) in sentences'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:35:in `upto'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:35:in `block in sentences'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:34:in `tap'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:34:in `sentences'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:42:in `paragraph'
/Users/gregorygrillone/Documents/personal_site/spec/fabricators/admin_user_audit_fabricator.rb:7:in `block (2 levels) in <top (required)>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/attribute.rb:40:in `instance_exec'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/attribute.rb:40:in `execute'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/attribute.rb:28:in `processed_value'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:102:in `block in process_attributes'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:101:in `each'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:101:in `process_attributes'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:6:in `build'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:20:in `create'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/definition.rb:75:in `block in fabricate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/definition.rb:74:in `instance_eval'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/definition.rb:74:in `fabricate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabricate.rb:29:in `create'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication.rb:62:in `Fabricate'
/Users/gregorygrillone/Documents/personal_site/db/seeds.rb:14:in `block in <top (required)>'
/Users/gregorygrillone/Documents/personal_site/db/seeds.rb:14:in `times'
/Users/gregorygrillone/Documents/personal_site/db/seeds.rb:14:in `<top (required)>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `block in load'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/railties-4.1.7/lib/rails/engine.rb:543:in `load_seed'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.7/lib/active_record/tasks/database_tasks.rb:184:in `load_seed'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.7/lib/active_record/railties/databases.rake:174:in `block (2 levels) in <top (required)>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:240:in `call'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:240:in `block in execute'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:235:in `each'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:235:in `execute'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/gregorygrillone/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:165:in `invoke'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:156:in `invoke_task'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:112:in `block (2 levels) in top_level'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:112:in `each'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:112:in `block in top_level'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:121:in `run_with_threads'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:106:in `top_level'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:84:in `block in run'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:182:in `standard_exception_handling'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:79:in `run'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/bin/rake:33:in `<top (required)>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/bin/rake:23:in `load'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/bin/rake:23:in `<main>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/bin/ruby_executable_hooks:15:in `eval'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/bin/ruby_executable_hooks:15:in `<main>'
I18n::MissingTranslationData: translation missing: en.faker.lorem.words
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/i18n-0.6.11/lib/i18n.rb:314:in `handle_exception'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/i18n-0.6.11/lib/i18n.rb:160:in `translate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker.rb:123:in `translate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:12:in `words'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:30:in `sentence'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:36:in `block (2 levels) in sentences'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:35:in `upto'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:35:in `block in sentences'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:34:in `tap'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:34:in `sentences'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/faker-1.4.3/lib/faker/lorem.rb:42:in `paragraph'
/Users/gregorygrillone/Documents/personal_site/spec/fabricators/admin_user_audit_fabricator.rb:7:in `block (2 levels) in <top (required)>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/attribute.rb:40:in `instance_exec'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/attribute.rb:40:in `execute'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/attribute.rb:28:in `processed_value'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:102:in `block in process_attributes'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:101:in `each'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:101:in `process_attributes'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:6:in `build'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/generator/base.rb:20:in `create'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/definition.rb:75:in `block in fabricate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/definition.rb:74:in `instance_eval'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication/schematic/definition.rb:74:in `fabricate'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabricate.rb:29:in `create'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/fabrication-2.11.3/lib/fabrication.rb:62:in `Fabricate'
/Users/gregorygrillone/Documents/personal_site/db/seeds.rb:14:in `block in <top (required)>'
/Users/gregorygrillone/Documents/personal_site/db/seeds.rb:14:in `times'
/Users/gregorygrillone/Documents/personal_site/db/seeds.rb:14:in `<top (required)>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `block in load'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/railties-4.1.7/lib/rails/engine.rb:543:in `load_seed'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.7/lib/active_record/tasks/database_tasks.rb:184:in `load_seed'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.7/lib/active_record/railties/databases.rake:174:in `block (2 levels) in <top (required)>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:240:in `call'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:240:in `block in execute'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:235:in `each'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:235:in `execute'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/gregorygrillone/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/task.rb:165:in `invoke'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:156:in `invoke_task'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:112:in `block (2 levels) in top_level'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:112:in `each'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:112:in `block in top_level'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:121:in `run_with_threads'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:106:in `top_level'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:84:in `block in run'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:182:in `standard_exception_handling'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/lib/rake/application.rb:79:in `run'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/gems/rake-10.4.0/bin/rake:33:in `<top (required)>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/bin/rake:23:in `load'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/bin/rake:23:in `<main>'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/bin/ruby_executable_hooks:15:in `eval'
/Users/gregorygrillone/.rvm/gems/ruby-2.1.4/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:seed

@ggrillone ggrillone changed the title Faker not loading when seeding data Faker translations missing when seeding data Dec 6, 2014
@ggrillone
Copy link
Author

I was exploring older issues and came across: #5

So I added I18n.reload! right after require 'faker', which resolved the above issue. Is this something new that is required to have? Just wondering because in other projects where I am using Faker I have never needed to add require 'faker' or I18n.reload!

@karlwilbur
Copy link
Contributor

I am seeing the same issue on multiple machines for multiple devs. We are trying to use Faker from the console to create a bunch of fake development data real fast. Seeing similar messages:

I18n::MissingTranslationData: translation missing: en.faker.blah.blah

For us, typing:

[4] pry(main)> require 'faker'
=> true
[5] pry(main)> I18n.reload!
=> nil
[6] pry(main)> 

...seems to work. Why isn't this just part of Faker when it loads?

[9] pry(main)> Faker::VERSION
=> "1.4.3"
[10] pry(main)> Rails.version
=> "4.1.4"
[11] pry(main)> 

@karlwilbur
Copy link
Contributor

This appears to be a duplicate of #278

adisandro added a commit to adisandro/Markus that referenced this issue Apr 28, 2016
 * Add production_test gemfile group, to cover gems that are not strictly
   needed in production, but still required to test a production-like
   deployment; an example is 'faker', to seed the database with test data
 * Fix rubric rake task to avoid faker-ruby/faker#285 when run in a production
   environment
@turboladen
Copy link

turboladen commented Sep 19, 2016

I get this too, FWIW, and I18n.reload! does the trick.

@vbrazo
Copy link
Member

vbrazo commented May 13, 2018

I'm closing this issue because it's pretty old and it seems that you guys have already found the solution. Feel free to reopen this issue if you have a problem again in the future 👍

@vbrazo vbrazo closed this as completed May 13, 2018
@karlwilbur
Copy link
Contributor

Yeah, it looks like the issue was caused by the failure to reload I18n. This seems to have been resolved by PR #811.

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

4 participants