Skip to content

authlogic-3.1.2 on rails 3.2.5 database connection issue #318

Closed
peterwillcn opened this Issue Jun 5, 2012 · 27 comments
@peterwillcn

bundle exec rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
You must establish a database connection before using acts_as_authentic
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/authlogic-3.1.2/lib/authlogic/acts_as_authentic/base.rb:31:in acts_as_authentic'
/var/www/com/web/tianjicom/app/models/admin/staffer.rb:4:in
class:Staffer'
/var/www/com/web/tianjicom/app/models/admin/staffer.rb:1:in <top (required)>'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:469:in
load'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:469:in block in load_file'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:639:in
new_constants_in'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:468:in load_file'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:353:in
require_or_load'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:502:in load_missing_constant'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:192:in
block in const_missing'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:190:in each'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:190:in
const_missing'
/var/www/com/web/tianjicom/app/models/admin/session.rb:2:in <class:Session>'
/var/www/com/web/tianjicom/app/models/admin/session.rb:1:in
'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:469:in load'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:469:in
block in load_file'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:639:in new_constants_in'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:468:in
load_file'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:353:in require_or_load'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:313:in
depend_on'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:225:in require_dependency'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/mongoid-2.4.10/lib/rails/mongoid.rb:73:in
load_model'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/mongoid-2.4.10/lib/rails/mongoid.rb:48:in block (2 levels) in load_models'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/mongoid-2.4.10/lib/rails/mongoid.rb:47:in
each'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/mongoid-2.4.10/lib/rails/mongoid.rb:47:in block in load_models'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/mongoid-2.4.10/lib/rails/mongoid.rb:46:in
each'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/mongoid-2.4.10/lib/rails/mongoid.rb:46:in load_models'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/mongoid-2.4.10/lib/mongoid/railtie.rb:120:in
block (2 levels) in class:Railtie'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:429:in _run__3436215260702108127__prepare__2843682175177248720__callbacks'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:405:in
__run_callback'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:385:in _run_prepare_callbacks'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:81:in
run_callbacks'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.5/lib/action_dispatch/middleware/reloader.rb:74:in prepare!'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.5/lib/action_dispatch/middleware/reloader.rb:48:in
prepare!'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/application/finisher.rb:47:in block in <module:Finisher>'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/initializable.rb:30:in
instance_exec'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/initializable.rb:30:in run'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/initializable.rb:55:in
block in run_initializers'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/initializable.rb:54:in each'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/initializable.rb:54:in
run_initializers'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/application.rb:136:in initialize!'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/railtie/configurable.rb:30:in
method_missing'
/var/www/com/web/tianjicom/config/environment.rb:5:in <top (required)>'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:in
require'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:in block in require'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:236:in
load_dependency'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:in require'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/application.rb:103:in
require_environment!'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/application.rb:292:in block (2 levels) in initialize_tasks'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in
call'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in block in execute'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in
each'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in execute'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in
block in invoke_with_call_chain'
/usr/local/ruby/ruby-1.9.3-194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in
invoke_with_call_chain'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:176:in block in invoke_prerequisites'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in
each'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in invoke_prerequisites'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:157:in
block in invoke_with_call_chain'
/usr/local/ruby/ruby-1.9.3-194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in
invoke_with_call_chain'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in invoke'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in
invoke_task'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in block (2 levels) in top_level'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in
each'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in block in top_level'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in
standard_exception_handling'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in top_level'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in
block in run'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in standard_exception_handling'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in
run'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in <top (required)>'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/bin/rake:23:in
load'
/var/www/com/web/tianjicom/vendor/bundle/ruby/1.9.1/bin/rake:23:in `

'
Tasks: TOP => db:migrate => environment

@peterwillcn

authlogic-3.1.2 on rails 3.2.5 "You must establish a database connection before using acts_as_authentic" issue

@tjeden
tjeden commented Jun 11, 2012

Some investigation about similar issue on stackoverflow: http://stackoverflow.com/questions/9518976/authlogic-doesnt-work-with-my-rails-3-2-app

@servebox

Experienced the same issue with both authlogic 3.1.2 and 3.1.1 with rails 3.2.x. It worked properly with 3.1.0.

The issue appears since modifications corresponding to commit ed6d8f3 whenever we reset our test database using rake. In our configuration, the test env loads factory_girl that in turn loads the User model. As rake is actually resetting the database, the db_setup? method returns false and the exception raises.

To fix the issue we rolled the Base module to the previous version.

@gsmendoza

I am also getting the error:

Given my Rails version is 3.1.5
And my Authlogic version is 3.1.2
And one of my models call acts_as_authentic
And my development database is empty
When I call a rake task that invokes the environment task e.g. db:schema:load, jasmine:ci
Then I get the following error at the model's acts_as_authentic call:
  You must establish a database connection before using acts_as_authentic
@hron
hron commented Jun 21, 2012

I've prepared a minimal rails application to illustrate this problem.

You will not get this error from the start if you do not use something that loads your models on environment preparation. This could be anything. For example an observer or ActiveAdmin which loads routes and triggers loading of models.

In my example we have the following things involved:

  • Rails 3.2.6
  • Authlogic 3.1.2
  • User model
  • UserObserver

So, just try to run rake db:migrate or rake db:setup you will get the following error:

% rake db:migrate
rake aborted!
You must establish a database connection before using acts_as_authentic

Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

I do not how to fix this properly, but it is definitely not expected behavior for a user. ;) Maybe is it possible to deffer configuration of authlogic to the phase when it is really need to be configured? I am not very familiar with Authlogic, but with some mentoring I can help with implementation.

Thank you in advance!

P.S. Ooops. I've just realized I forgot to mention where to find the example. ;)

https://github.com/hron/authlogic-raising-on-acts_as_authentic-problem-example

@james2m
james2m commented Jul 12, 2012

Until Ben has time to merge the fix above you can work around this using the fixed branch in your Gemfile;

gem 'authlogic', :git => 'git@github.com:james2m/authlogic.git', :branch => 'fix-migrations'
@dpritchett

Alternate workaround: I commented out the acts_as_authentic blocks in my models just long enough to successfully run rake db:migrate and then uncommented the same blocks.

@Nitrodist

How about a merge on this fix?

@maletor
maletor commented Aug 27, 2012

@binarylogic, merge would be appreciated.

@gokulnath

+1

@maletor
@gokulnath

ha, just saw that. But I was getting the "You must establish a database connection before using acts_as_authentic" error in production.

@davydotcom

This is still broken?

@harmon
harmon commented Sep 12, 2012

Yes, please merge! I reverted back to authlogic 3.1.0 with rails 3.2.8 and it fixes the issue. I will stay on 3.1.0 for now.

@jherdman

Ping @yourewelcome. A quick merge and patch release on this would be awesome. I have some crappy "sed" hacks in my migration code now just to get around this.

@brainstormhq

Yup. Just use 3.1.0 for now

@ghost
ghost commented Oct 2, 2012

+1

@snoblenet

+1

@bloudermilk

Please merge!

@binarylogic binarylogic pushed a commit that closed this issue Oct 23, 2012
@james2m james2m Fixes #318 and fixes #322 broken migrations caused by #290.
Signed-off-by: James McCarthy <james2mccarthy@gmail.com>
d1fdc90
@maukoquiroga

¿Is this already fixed or not?

@james2m
@gvt
gvt commented Nov 8, 2012

+1

@binarylogic
Owner

I merged this in...

@gvt
gvt commented Nov 21, 2012

which version of the authlogic gem will it be in?

@corejh
corejh commented Nov 21, 2012

I see. I had to pull from the master branch to get this update. changed this in my gemfile:

gem 'authlogic', :git => 'git://github.com/binarylogic/authlogic.git'

Thanks @james2m and @yourewelcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.