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

Precompile tries to access the database on acceptance validation #11381

Closed
willc0de4food opened this issue Jul 9, 2013 · 23 comments
Closed

Precompile tries to access the database on acceptance validation #11381

willc0de4food opened this issue Jul 9, 2013 · 23 comments

Comments

@willc0de4food
Copy link

@willc0de4food willc0de4food commented Jul 9, 2013

I have a validation that checks to make sure a checkbox is checked. When I try to precompile assets, it's hitting that validation, attempting to access the database, and failing (I'm deploying this app to Heroku, so this isn't going to work). This seems to be the culprit: https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/attribute_methods.rb#L99
I do have config.assets.initialize_on_precompile = false in my application.rb. Here's a gist of the code I'm referencing: https://gist.github.com/willc0de4food/ca3c78f149dc5c425dcd
I also attempted to wrap the validation in ActiveSupport.on_load, with the same problem: https://gist.github.com/willc0de4food/3c48c5e4a2efb938b3b1

@pftg

This comment has been minimized.

Copy link
Contributor

@pftg pftg commented Jul 9, 2013

Do you have any initializers, which require Contract model?
Also as I understand you use rails 4.0.0_, if I'm right you do not need config.assets.initialize_on_precompile = false.

@willc0de4food

This comment has been minimized.

Copy link
Author

@willc0de4food willc0de4food commented Jul 9, 2013

Good to know, thanks.
The only initializer I have that might try, is the rails_admin initializer, but I'm telling it to blacklist the contract model: https://gist.github.com/willc0de4food/786b86ae8bc8bbe27eb9

@pftg

This comment has been minimized.

Copy link
Contributor

@pftg pftg commented Jul 9, 2013

hmm, elsewhere, some from your engines require 'Contractor' model on environment loading. I blame on rails_admin, but cannot say for sure. If you have complete rails examples, because by info which you have provided I cannot reproduce your problem. Default generated rails app with rails admin do not load any models.

@willc0de4food

This comment has been minimized.

Copy link
Author

@willc0de4food willc0de4food commented Jul 9, 2013

@steveklabnik

This comment has been minimized.

Copy link
Member

@steveklabnik steveklabnik commented Jul 9, 2013

Rails (like all of us 😉) is innocent until proven guilty. As @pftg mentions, it doesn't appear that this is Rails' issue. If you can reproduce this with vanilla Rails, please show that to us and we can re-open, but until then, this isn't a bug.

@willc0de4food

This comment has been minimized.

Copy link
Author

@willc0de4food willc0de4food commented Jul 9, 2013

https://github.com/willc0de4food/checkbox_acceptance_test

That's a pretty bare-bones app, and RAILS_ENV=production bundle exec rake assets:precompile is failing with the same error.

@pftg

This comment has been minimized.

Copy link
Contributor

@pftg pftg commented Jul 9, 2013

@willc0de4food I think you have point. I'm investigating why in your app acceptance validator breaks rake assets:precompile

@pftg

This comment has been minimized.

Copy link
Contributor

@pftg pftg commented Jul 9, 2013

just for notice, this only happens in your app.

@willc0de4food

This comment has been minimized.

Copy link
Author

@willc0de4food willc0de4food commented Jul 9, 2013

Weird. Lol, so my Rails is the only one that's broken :[ Oh well. Just as an FYI, I can recreate this scenario every time on my machine: https://github.com/willc0de4food/checkbox_acceptance_test2

@pftg

This comment has been minimized.

Copy link
Contributor

@pftg pftg commented Jul 9, 2013

I created test case, so all models inherited from ActiveRecord::Base preloaded. So this is problem.

@mitchkett

This comment has been minimized.

Copy link

@mitchkett mitchkett commented Jul 9, 2013

I can recreate after cloning his repo, cd into directory, run bundle install, then RAILS_ENV=production bundle exec rake assets:precompile

rake aborted!
Unknown database 'checkbox_test2_production'
/Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in connect' /Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:ininitialize'
/Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in new' /Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:inmysql2_connection'
/Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in new_connection' /Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:incheckout_new_connection'
/Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in acquire_connection' /Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:inblock in checkout'
/Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in checkout' /Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:inblock in connection'
/Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in connection' /Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:inretrieve_connection'
...

@mitchkett

This comment has been minimized.

Copy link

@mitchkett mitchkett commented Jul 9, 2013

The error does not get thrown if you run the rake command for development or test, just production.

@pftg

This comment has been minimized.

Copy link
Contributor

@pftg pftg commented Jul 9, 2013

I think, because eager_load! automatically invoked for production.

@pftg

This comment has been minimized.

Copy link
Contributor

@pftg pftg commented Jul 9, 2013

For now added fixed tests. Will continue investigation on eager loaded modules for production env.

@miry

This comment has been minimized.

Copy link

@miry miry commented Jul 9, 2013

Try to set config.assets.initialize_on_precompile = false in config/application.rb. http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

@willc0de4food

This comment has been minimized.

Copy link
Author

@willc0de4food willc0de4food commented Jul 9, 2013

@miry

This comment has been minimized.

Copy link

@miry miry commented Jul 9, 2013

@willc0de4food try this patch #11384

@willc0de4food

This comment has been minimized.

Copy link
Author

@willc0de4food willc0de4food commented Jul 10, 2013

Are there instructions somewhere on the process of apply such a patch?

@miry

This comment has been minimized.

Copy link

@miry miry commented Jul 10, 2013

@willc0de4food replace config.eager_load = true with config.eager_load = true if config.eager_load.nil?

@pftg

This comment has been minimized.

Copy link
Contributor

@pftg pftg commented Jul 10, 2013

I added PR #11389 with fixing bug for rake and fixing tests.

@willc0de4food

This comment has been minimized.

Copy link
Author

@willc0de4food willc0de4food commented Jul 10, 2013

@miry that worked. No more error. I didn't realize you meant in the app's environment file :X

pftg added a commit to jetthoughts/rails that referenced this issue Jul 10, 2013
josevalim added a commit that referenced this issue Jul 10, 2013
…precompile

 #11381: Ignore config.eager_load=true for rake
josevalim added a commit that referenced this issue Jul 10, 2013
…precompile

 Closes #11381: Ignore config.eager_load=true for rake
@guilleiguaran

This comment has been minimized.

Copy link
Member

@guilleiguaran guilleiguaran commented Jul 10, 2013

config.assets.initialize_on_precompile isn't supported in Rails 4 anymore 😁

@gugl

This comment has been minimized.

Copy link

@gugl gugl commented Jul 22, 2014

looks like there is a reference to #11853
i also added a way to reproduce the issue. https://github.com/gugl/virtattr
any ideas for solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

7 participants
You can’t perform that action at this time.