authlogic: Authlogic stops working with config.eager_load = true
I have the (monstrous) task of upgrading a project from Ruby 1.8.7 to 2.2.2 and Rails 3.2.18 to 4.2. Things were going pretty well, the development environment was ok, so I decided to try out the production environment… good feeling gone.
When I try to save my session, I get:
undefined method `valid_password?'
After quite some time debugging the issue, I noticed that everything works fine if I change the Rails setting config.eager_load to false.
It seems that the methods normally dynamically added by Authlogic to my Operator model class aren’t there. Does anyone have a clue how to fix this?
About this issue
- Original URL
- State: closed
- Created 12 years ago
- Comments: 24 (9 by maintainers)
For those wondering.
6.5.0now works correctly with eager loading.I dug a bit deeper and I think the problem might lie here:
https://github.com/binarylogic/authlogic/blob/d155fff4672595af99cb3488d9731f1efc595049/lib/authlogic/acts_as_authentic/base.rb#L84-L90
It silently stops including modules if
column_namesraises an error. These days there are better ways to hook into the lifecycle of Rails initialisation, but sadly I don’t think it’s worth pursuing a fix unless we can see some action from the maintainers around maintenance of this gem.@yvbeek, I need to buy you a beer or something. You’ve saved me probably many hours of toil trying to figure this one out. I have a multi-tenant application also with a very simple database switcher:
Wrapping the authlogic setup as you mention and calling
User.setup_authlogicafterreconnect!seems to have done the trick. I assume there’s a race condition here. I’ve only encountered this issue after upgrading from Rails 6.2 to 8.0 and incorporatingActiveSupport::CurrentAttributeswhich I suspect loads the user much earlier in the process.My symptoms were that I’d get the error after rebooting the server, but doing a deploy with Capistrano that restarted my Passenger instances would seem to fix, or partially fix things. Very weird.
Thank you for taking the time to record your solution.