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

ActiveRecord dependency causes rake assets:compile to fail without access to a database #84

Closed
mattheworiordan opened this issue May 6, 2013 · 9 comments

Comments

@mattheworiordan
Copy link

When I include the gem acts_as_list in my Gemfile, intentionally change my connection string for PostgreSQL database to an invalid DB, and run rake assets:precompile, I receive an ActiveRecord error. It appears that acts_as_list tries to connect to the database at all times, even during asset compilation.

If you refer to the Heroku post at https://devcenter.heroku.com/articles/rails-asset-pipeline, you will see that this problem unfortunately makes acts_as_list incompatible with Heroku.

I have worked around the problem by doing something along the lines of:

gem 'acts_as_list', require: false

And I have an initializer which does this:

require 'acts_as_list' unless Rails.groups.include?('assets')

Here is the error log which unfortunately does not clearly show where the problem lies:

$ rake assets:precompile
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/bin/ruby /Users/matt/.rvm/gems/ruby-1.9.3-p286/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
FATAL:  database "mysite_deploymenta" does not exist
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/model_schema.rb:308:in `clear_cache!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.12/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:418:in `_run__3455161023029107272__prepare__737315814947044187__callbacks'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/matt/Dropbox/Projects/easybacklog/easybacklog/config/environment.rb:5:in `<top (required)>'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.12/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.12/lib/sprockets/assets.rake:93:in `block (2 levels) in <top (required)>'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:205:in `block in invoke_prerequisites'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:203:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:203:in `invoke_prerequisites'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:183:in `block in invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.12/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
Tasks: TOP => environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/matt/.rvm/rubies/ruby-1.9.3-p286/bi...]
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `call'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `sh'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `sh'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/file_utils.rb:80:in `ruby'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `ruby'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.12/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.12/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.12/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
@josal
Copy link

josal commented Oct 17, 2013

I faced this problem when installing Spree in heroku (Rails 4). This gem doesn't allow to deploy spree in heroku AFAIK.

@brendon
Copy link
Owner

brendon commented Apr 17, 2016

Sorry to hear that this is the case. I'd like to look into this. Can you confirm it's still a problem with master? If you can trace the query that's being executed when acts_as_list is being initialised that would be helpful. I assume that's what's happening?

@swanandp
Copy link
Collaborator

I haven't faced this problem before, and I have has a bunch of apps on Heroku with acts_as_list. Definitely need some more information to understand what's happening.

@brendon
Copy link
Owner

brendon commented Jun 2, 2016

Closing for now. @mattheworiordan, please feel free to contribute further if it's still a problem for you.

@brendon brendon closed this as completed Jun 2, 2016
@felixbuenemann
Copy link

I'm running into the same issue when building a docker container for a solidus app where the database connection is not available when rake assets:precompileis run.

The acts_as_list gem accesses the active record connection in a class method which triggers a database connection:

https://github.com/swanandp/acts_as_list/blob/v0.8.0/lib/acts_as_list/active_record/acts/list.rb#L77

quoted_position_column = connection.quote_column_name(configuration[:column])

Looking at the master branch this method is now lazily evaluated, so it might be fixed in the next version:

https://github.com/swanandp/acts_as_list/blob/master/lib/acts_as_list/active_record/acts/list.rb#L112

@brendon Could you re-open this issue until a fixed version is released?

@felixbuenemann
Copy link

Reading the code on master more carefully, it doesn't seem to be fixed, because those methods are still called inside the class method duringdefine_singleton_method calls.

@brendon
Copy link
Owner

brendon commented Sep 5, 2016

That's interesting. Are you able to test it out and let me know? Perhaps there's a way to quote without using the method via the connection?

@brendon brendon reopened this Sep 5, 2016
@felixbuenemann
Copy link

I switched to master and it seems to work, from reading the code I would have thought that the methods would still be called when the acts_as_list class method is invoked.

@brendon
Copy link
Owner

brendon commented Sep 6, 2016

Thanks @felixbuenemann, I think that one is only evaluated when the method is actually called. It's certainly difficult to read in its current state.

I'll close this since the latest seems to support what you're after. I'll release a new version now too.

@brendon brendon closed this as completed Sep 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants