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

I get "KeyError: key not found" . #143

Open
real-ashwin opened this issue May 29, 2015 · 24 comments
Open

I get "KeyError: key not found" . #143

real-ashwin opened this issue May 29, 2015 · 24 comments

Comments

@real-ashwin
Copy link

I am not an expert in rails, but here's the stack trace.

It occurs just after "run bundle exec rake db:migrate from "."" and happens for all future "rake" commands.

rake
rake aborted!
KeyError: key not found
(erb):18:in `fetch'
(erb):18:in `<main>'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/application.rb:391:in `secrets'
/Users/ashwin/Documents/workspace/rails-starter/rails-stripe-membership-saas/config/initializers/devise.rb:15:in `block in <top (required)>'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.5.1/lib/devise.rb:281:in `setup'
/Users/ashwin/Documents/workspace/rails-starter/rails-stripe-membership-saas/config/initializers/devise.rb:3:in `<top (required)>'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/engine.rb:615:in `each'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/engine.rb:615:in `block in <class:Engine>'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `each'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `tsort_each_child'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
/Users/ashwin/Documents/workspace/rails-starter/rails-stripe-membership-saas/config/environment.rb:5:in `<top (required)>'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/ashwin/Documents/workspace/rails-starter/rails-stripe-membership-saas/test/test_helper.rb:2:in `<top (required)>'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/ashwin/Documents/workspace/rails-starter/rails-stripe-membership-saas/test/models/user_test.rb:1:in `<top (required)>'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:114:in `each'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:113:in `each'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
/Users/ashwin/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.1/lib/rails/test_unit/testing.rake:8:in `block in <top (required)>'
Tasks: TOP => test:run
(See full trace by running task with --trace)
@DanielKehoe
Copy link
Member

You need to set the MAILCHIMP_API_KEY and STRIPE_API_KEY values in either your Unix ENV variables or the config/secrets.yml file.

@real-ashwin
Copy link
Author

Hey Daniel, Thanks for the quick reply but unfortunately that did not fix it :( ..

@rsgrafx
Copy link

rsgrafx commented May 29, 2015

Open terminal and at the command line $> source ~/.bash_profile or ~/.profile. at the command prompt and type `echo $MAILCHIMP_API_KEY - or any of the keys in question. if you see the key you specified. restart rails.

@real-ashwin
Copy link
Author

I can see the key but the error still exists .
On May 29, 2015 12:09 AM, "Orion Engleton" notifications@github.com wrote:

Open terminal and at the command line $> source ~/.bash_profile or
~/.profile. at the command prompt and type `echo $MAILCHIMP_API_KEY if you
see the key you specified. restart rails.


Reply to this email directly or view it on GitHub
#143 (comment)
.

@rsgrafx
Copy link

rsgrafx commented May 29, 2015

I'm getting the same error cant find the issue myself .. this is after doing a search and commenting out all blocks of code where I see Rails.application.secrets.whatever_key , in the initializers - in the user model in the secrets.yml. Just to get the first initial migration going.

$> rake db:migrate

rake aborted!

KeyError: key not found: "MAILCHIMP_API_KEY"
(erb):20:in `fetch'
(erb):20:in

@DanielKehoe
Copy link
Member

In your config/secrets.yml file, replace the following:

  mailchimp_api_key: <%= ENV.fetch("MAILCHIMP_API_KEY") %>
  mailchimp_list_id: <%= ENV.fetch("MAILCHIMP_LIST_ID") %>
  stripe_api_key: <%= ENV.fetch("STRIPE_API_KEY") %>
  stripe_publishable_key: <%= ENV.fetch("STRIPE_PUBLISHABLE_KEY") %>

with:

  mailchimp_api_key: yourkey
  mailchimp_list_id: yourlistid
  stripe_api_key: yourkey
  stripe_publishable_key: yourkey

If you are having trouble with Unix ENV variables you don't have to use them. Just put the values into your config/secrets.yml file. But don't check it into git, just diagnose the problem by hardcoding the values.

@real-ashwin
Copy link
Author

@rsgrafx Did you manage to fix this issue?
@DanielKehoe Can we 'open' this issue?

@DanielKehoe DanielKehoe reopened this May 30, 2015
@DanielKehoe
Copy link
Member

I've reopened the issue as requested. Is there anyone who has not been able to resolve the issue by setting the Unix ENV variables or hardcoding the vales in the config/secrets.yml file?

@nikolay12
Copy link

I haven't been able, either. I changed quite a few things and made it to work. Will commit to the fork and than try to diff to find out what is it that made it work.

==EDIT: just pushed my changes to my fork - you can have a look at the differences - it should be in the config directory. I've excluded the files containing sensitive data (the *yml ones) - I can give you a censored version of them, too - if necessary.

@DanielKehoe
Copy link
Member

The only purpose of the fetch method is to force an error if the API keys are not available in the Unix ENV variables when the application is started. This lets the developer know that the API key is not available and avoids more mysterious errors later. You can remove the fetch method from the config/secrets.yml file and the application will run without the initial error. But it will fail later if the API key is not available.

See 3fce464

@real-ashwin
Copy link
Author

@DanielKehoe More info : I get this error while running the composer command $ rails new rails-stripe-membership-saas -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

The errors don't go away even after adding the API keys in the environment variables.

@DanielKehoe
Copy link
Member

@ashwinputhige Could you clarify please, do you get the I get "KeyError: key not found" when the Rails Composer script is running (causing a failure before an app is created)? Or do you build an app using Rails Composer successfully, and then get the error when you launch the app with rails server?

@real-ashwin
Copy link
Author

I get it when the rails composer script is running before the app is created. It happens at the command bundle exec rake db:command (I believe its db:migrate). I can retry if that is important.

@DanielKehoe
Copy link
Member

Thank you @ashwinputhige, that is helpful.

@DanielKehoe
Copy link
Member

I've released a new version of Rails Composer that removes the fetch method from the config/secrets.yml file. @ashwinputhige please give it a try and let me know if the issue is resolved.

@kathyonu
Copy link
Contributor

@ashwinputhige : This note replaced with my next comment.

@kathyonu
Copy link
Contributor

kathyonu commented Jul 1, 2015

@ashwinputhige @nikolay12 @rsgrafx : Please see PR Testsformaster #150 . I invite you to pull this branch into your working app, and take it for a spin. You will see it has tests that resolve Issue #143 . If you can help resolve the four pending tests, that would be grand, thank you.

@real-ashwin
Copy link
Author

@kathyonu Sorry, I am not using this application and so I will not be able to run your tests. Please feel free to close the issue if required.

@nikolay12
Copy link

I just git cloned the repository - the problem still persists. I cancelled my Railsapp subscription - sorry Daniel, it just does not make sense to continue paying for something that is so brittle.

@kathyonu
Copy link
Contributor

@nikolay12 @ashwinputhige @rsgrafx @DanielKehoe Greetings .. I have changed my mind, ashwinputhige, and nikolay12 I ask you to change yours too .. If you will look at Issue #152, specifically the posts i made there yesterday ..you will find a resource that really is priceless in these matters of setting the enviroment variables. So that you know, I have an in production rails-stripe-membership-saas running sweet as can be, and I have gone through the exact same issues you are facing and I can easily help resolve them for you .. and others you may run into. Please re-signup with RailsApps if need be and accept this offer of help and you will have a high power fully-tested app at your fingertips .. the tests are arriving as referred to in Issue #152 and more to come. We are also going to be adding capabilities after what exists is fully tested.

@ysksn
Copy link

ysksn commented Nov 18, 2015

try this :)
bin/spring stop

@UbuntuEvangelist
Copy link

screenshot from 2019-01-31 19-33-33
same problem using ubuntu 16

@aliwaqar981
Copy link

Getting same error. Any solution?

@pmutale
Copy link

pmutale commented Apr 7, 2021

Here too! This was working until I updated rails to 6.1

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

9 participants