lyang / braintree-rails

MIT License
65 stars 22 forks source link

Odd: uninitialized constant BraintreeRails::CreditCard::BillingAddress #16

Closed mbhnyc closed 10 years ago

mbhnyc commented 10 years ago

Just tried to run console on an app with this gem deployed, and see the following exception:

Look familiar to anyone?

/app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/credit_card.rb:17:in `<class:CreditCard>': uninitialized constant BraintreeRails::CreditCard::BillingAddress (NameError)
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/credit_card.rb:2:in `<module:BraintreeRails>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/credit_card.rb:1:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/customer.rb:15:in `<class:Customer>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/customer.rb:2:in `<module:BraintreeRails>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/customer.rb:1:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/address.rb:11:in `<class:Address>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/address.rb:2:in `<module:BraintreeRails>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/address.rb:1:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/billing_address.rb:2:in `<module:BraintreeRails>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/billing_address.rb:1:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/transaction.rb:23:in `<class:Transaction>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/transaction.rb:2:in `<module:BraintreeRails>'
    from /app/vendor/bundle/ruby/2.0.0/bundler/gems/braintree-rails-1cb47e589289/lib/braintree_rails/transaction.rb:1:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies/autoload.rb:43:in `block in eager_autoload!'
    from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies/autoload.rb:43:in `each'
    from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies/autoload.rb:43:in `eager_autoload!'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/application/bootstrap.rb:20:in `block in <module:Bootstrap>'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/initializable.rb:30:in `instance_exec'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/initializable.rb:30:in `run'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/initializable.rb:54:in `each'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/initializable.rb:54:in `run_initializers'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/application.rb:136:in `initialize!'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /app/config/environment.rb:5:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/application.rb:103:in `require_environment!'
    from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.14/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
lyang commented 10 years ago

Hi @mbhnyc , Not sure about your ruby's version and patch level, I tried locally with MRI 2.0.0p353 with Rails 3.2.13/4/6. However I wasn't able to reproduce the error you have seen.

Have you seen this error before? What about other environments?

mbhnyc commented 10 years ago

No I have not, and the issue does not occur in non-production environments!

Running 3.2.16 and the same Ruby.

Any ideas?

lyang commented 10 years ago

Hi @mbhnyc , I've tried all combinations of environments I have access to and still can't reproduce the issue. I'm assuming your prod rails server doesn't have this issue, correct? Is the error only bubble up in prod rails console? Were you running bundle exec rails console? What about bundle exec rails runner?

mbhnyc commented 10 years ago

We're about to do a push to production with some unrelated changes (and ruby 2.1) and will try this again afterwards and report back!

mbhnyc commented 10 years ago

No, this is ONLY occurring in Production! Ok, this is actually preventing rake from running my migrations, which is a bit troubling.

mbhnyc commented 10 years ago

I'm in with the console if I run bundle exec rails console, but bundle exec rake db:migrate still fails.

mbhnyc commented 10 years ago

Ok, I dropped back to the 1.2 gem version, which resolved the issue for now (at least so I could complete my deployment). I'll dive in a little and see if I can figure this out.

lyang commented 10 years ago

Just to clarify, the correct rails env is set, right? e.g RAILS_ENV=prod bundle exec ... or bundle exec rails console prod

mbhnyc commented 10 years ago

Well: RACK_ENV=production and RAILS_ENV=production but yes.

Hmm, not sure why I have both of those set.

tmak commented 10 years ago

I had the same problem in my Rails 4 app. Adding BraintreeRails.eager_load! to my braintree rails initializer file fixed it for me. Hope that helps.

tmak commented 10 years ago

Hmm, it seems to be a random order problem of requiring the braintree-rails files. Now it only happens occasionally in my rake tasks after adding BraintreeRails.eager_load! to my braintree rails initializer file.

tmak commented 10 years ago

That's how I can reproduce the error, even without rails.

Works:

require 'braintree-rails'

BraintreeRails::CreditCard
BraintreeRails::Transaction

Doesn't work:

require 'braintree-rails'

BraintreeRails::Transaction

@lyang Can you confirm that?

lyang commented 10 years ago

@tmak, Yes, I can confirm. Working on a fix now.

Thank you very much for the feedback!

mbhnyc commented 10 years ago

Yay! So glad a fix is in the works.

lyang commented 10 years ago

@mbhnyc, @tmak A fix has been checked into the master branch yesterday.

Would you mind try it out and let me know if it fixes the error?

Thanks!

tmak commented 10 years ago

@mbhnyc works for me, thanks!

mbhnyc commented 10 years ago

Next time I do a deploy to production i'll update the gem and report back, sounds like we can close for now though. :+1: