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

engine.rb early loading: 'method_missing': undefined local variable or method #1192

Closed
ridem opened this issue May 25, 2016 · 7 comments
Closed
Assignees
Labels
type:bug Error, flaw or fault
Milestone

Comments

@ridem
Copy link
Contributor

ridem commented May 25, 2016

After the commit that set up all initializers before config/init, I couldn't run the server because act_as_lists was not loaded at that point in time:

The server crashed with a 'method_missing': undefined local variable or method error there https://github.com/solidusio/solidus/blob/master/core/lib/spree/core/engine.rb#L48 while trying to load acts_as_list'

The only way around this was for me to explicitly require acts_as_list in my Gemfile so it gets required earlier.
Can someone confirm this issue?

@jhawthorn
Copy link
Contributor

@ridem Thanks for reporting (and testing on our master branch 😄 )

I haven't been able to reproduce this. I'd expect acts_as_list to be required here, before the engine is loaded.

Could you post your Gemfile and ruby version or anything else that might help us reproduce this?

@ridem
Copy link
Contributor Author

ridem commented May 26, 2016

Thanks for your answer! I was actually on the v1.3 branch when it happened, the same problem occurred because it was the same commit.

Here's the full backtrace:

=> Booting Puma
=> Rails 4.2.6 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server

/usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.6/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined local variable or method `acts_as_list' for #<Class:0x007fe7aa3d18e8> (NameError)
    from /path/to/solidus/master/core/app/models/spree/payment_method.rb:4:in `<class:PaymentMethod>'
    from /path/to/solidus/master/core/app/models/spree/payment_method.rb:2:in `<module:Spree>'
    from /path/to/solidus/master/core/app/models/spree/payment_method.rb:1:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:457:in `load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:457:in `block in load_file'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:647:in `new_constants_in'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:456:in `load_file'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:354:in `require_or_load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:494:in `load_missing_constant'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:184:in `const_missing'
    from /path/to/solidus/master/core/app/models/spree/gateway.rb:2:in `<module:Spree>'
    from /path/to/solidus/master/core/app/models/spree/gateway.rb:1:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:457:in `load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:457:in `block in load_file'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:647:in `new_constants_in'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:456:in `load_file'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:354:in `require_or_load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:494:in `load_missing_constant'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:184:in `const_missing'
    from /path/to/solidus/master/core/lib/spree/core/engine.rb:48:in `block in <class:Engine>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:44:in `each'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:413:in `call'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:44:in `each'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:413:in `call'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:44:in `each'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:413:in `call'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:345:in `each'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:345:in `call'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
    from /path/to/my/solidus/project/config/environment.rb:5:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
    from /path/to/my/solidus/project/config.ru:3:in `block in <main>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
    from /usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
    from /path/to/my/solidus/project/config.ru:in `new'
    from /path/to/my/solidus/project/config.ru:in `<main>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
    from /usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
    from /usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
    from /usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
    from /usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/server.rb:61:in `app'
    from /usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/server.rb:139:in `log_to_stdout'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/server.rb:78:in `start'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
    from /path/to/my/solidus/project/bin/rails:8:in `require'
    from /path/to/my/solidus/project/bin/rails:8:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `call'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/command.rb:7:in `call'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client.rb:30:in `run'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/bin/spring:49:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `<top (required)>'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/Cellar/ruby22/2.2.4/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /path/to/my/solidus/project/bin/spring:13:in `<top (required)>'
    from /path/to/my/solidus/project/bin/rails:3:in `load'
    from /path/to/my/solidus/project/bin/rails:3:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

If it can help, here is my Gemfile:

source 'https://rubygems.org'

ruby '2.2.4'

gem 'rails', '~> 4.2.6'
gem 'pg'
gem 'sass-rails'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'therubyracer', platforms: :ruby

# ActiveModelSerializers
gem 'active_model_serializers', '~> 0.10.0'

# Use Puma as the app server
gem 'puma'

group :development, :test do
  gem 'foreman'
  gem 'rails_real_favicon'
  gem 'pry'
  gem 'pry-remote'
  gem 'pry-stack_explorer'
  gem 'pry-nav'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'awesome_print'

  gem 'spring'

  # testing
  gem 'rspec-rails', '~> 3.0'
  gem 'rspec-activemodel-mocks'
  gem 'rspec-activejob'
  gem 'spring-commands-rspec'
  gem 'shoulda-matchers', require: false
  gem 'factory_girl'
  gem 'factory_girl_rails'
  gem 'database_cleaner'
  gem 'ffaker'
  gem 'quiet_assets'
  gem 'bullet'
end

gem 'web-console', '~> 3.0', group: :development

group :test do
  gem 'capybara'
  gem 'capybara-screenshot'
  gem 'launchy'
  gem 'vcr'
  gem 'webmock'
  gem 'test_after_commit'
  gem 'codeclimate-test-reporter', require: nil
end

# Heroku fixes
group :production, :staging do
  gem 'rails_12factor'
  gem 'rack-timeout'
  gem 'font_assets', github: 'masterexploder/font_assets'
  # Password-protected for staging
  gem 'lockup'
end

# File uploads - Amazon
gem 'paperclip'
gem 'aws-sdk', '< 2.0'
gem 'fog-aws'
gem 'dragonfly-s3_data_store'

# Caching
gem 'dalli' # memcache
gem 'rack-cache' # http caching
gem 'kgio' # faster kgio IO system

# Rollbad
gem 'rollbar'

# New Relic
# gem 'newrelic_rpm'

# Tasks
gem 'sidekiq'
gem 'sinatra', require: nil

# Front end
gem 'haml'
gem 'react-rails'
gem 'js-routes'
gem 'i18n-js', '>= 3.0.0.rc11'

# Solidus
gem 'solidus', github: 'solidusio/solidus', branch: 'v1.3'
gem 'solidus_auth_devise', github: 'solidusio/solidus_auth_devise'
gem 'solidus_gateway', github: 'solidusio/solidus_gateway'
gem 'braintree'
gem 'solidus_braintree'

# CMS
gem 'alchemy-solidus', github: 'AlchemyCMS/alchemy-solidus', branch: 'master'
gem 'alchemy_cms', github: 'ridem/alchemy_cms', branch: 'ams-0.10'

I tried again today, and can confirm that the issue appeared after this commit.

@deodad
Copy link
Contributor

deodad commented May 26, 2016

@ridem is there somewhere in your application that you are performing configuration before the engine is loaded, something similar to: app.config.spree.payment_methods << Solidus::Gateway::OtherGateway?

@jhawthorn jhawthorn added this to the 1.3.0 milestone May 26, 2016
@jhawthorn
Copy link
Contributor

Thanks. I can reproduce from that Gemfile

@jhawthorn jhawthorn self-assigned this May 26, 2016
@jhawthorn jhawthorn added the type:bug Error, flaw or fault label May 26, 2016
@jhawthorn
Copy link
Contributor

As far as I can tell adding react-rails is what triggers this failure. Still investigating to see what we can do to work around it.

@ridem
Copy link
Contributor Author

ridem commented May 27, 2016

Thanks for the investigation @jhawthorn !

@jhawthorn
Copy link
Contributor

This should be fixed by #1203 which is now in the v1.3 branch. We'll probably have another beta release shortly.

Thanks again for reporting the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Error, flaw or fault
Projects
None yet
Development

No branches or pull requests

3 participants