Models can't be used in migrations if config.threadsafe! is set #2662

schuetzm opened this Issue Aug 23, 2011 · 7 comments

6 participants


It seems, autoloading is disabled then.

However, Bruce Adams suggested a workaround here:
which is to put "config.threadsafe! unless $rails_rake_task" into your environment file.

I suggest to insert this into the default files that are created with a new application.


@schuetzm Is this still an issue?


Yes, seems so. Steps to reproduce:
1. create new rails app (3.2.3)
2. insert "config.threadsafe!" in config/environments/development.rb
3. create migration file db/migrate/20120428210253_add_xxx.rb:


class AddXxx < ActiveRecord::Migration
  def up

  def down
  1. create app/model/xxx.rb and app/model/blabla.rb with dummy classes Xxx and Blabla
  2. run rake db:migrate => error "uninitialized constant Blabla"
  3. if you use "config.threadsafe! unless $rails_rake_task" in the environment file instead, the classes will be auto-loaded

(note also that it has already loaded the class Xxx, probably because that's what the migration is named)


Another way to work around this issue is to explicitly require the necessary models

Ruby on Rails member

Given @tenderlove's recent interest in making config.threadsafe! the default, this ticket is probably of interest.

It seems, autoloading is disabled then.

That is true. Autoloading isn't threadsafe.


This should at minimum throw a loud warning since it's going to break a lot of people's existing migrations.

Ruby on Rails member

Fixed on master! \o/

@josevalim josevalim closed this Sep 7, 2012

@josevalim Rocking, thanks.

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