Fix preinitialization errors in gems like has_many_polymorphs #18

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
2 participants
@ahawkins

ahawkins commented Dec 1, 2010

I've got a project that uses has many polymorphs. When Rails is loaded it connects to the DB to look at columns to preload all the stuff it needs to create its relation. This caused a problem with specjour since load_app (in Worker) is called before Configuration.after_fork. So when load_app was called, ENV['TEST_ENV_NUMBER'] is present which changes the database. However, since the default after_fork(DBScrub) is called after the app was loaded this created a state where the forked Rails app is trying to access a DB that isn't created yet. I think this may also solve a problem with ActiveScaffold which does roughly the same thing. When a ActiveScaffold controller is loaded it connects to the db to read column information (which will cause a problem if the DB is not created).

tl;dr: moved Configuration.after_fork.call to before load_app to fix issues with libraries that connect to the DB when files are loaded

@sandro sandro closed this Jan 7, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment