diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 7a8c4d0..3e85655 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -465,7 +465,16 @@ class Module #:nodoc: # Use const_missing to autoload associations so we don't have to # require_association when using single-table inheritance. def const_missing(class_id) - ActiveSupport::Dependencies.load_missing_constant self, class_id + c = Thread.critical + Thread.critical = true + begin + const = ActiveSupport::Dependencies.load_missing_constant self, class_id + rescue + Thread.critical = c + raise + end + Thread.critical = c + const end def unloadable(const_desc = self) @@ -476,23 +485,32 @@ end class Class def const_missing(const_name) - if [Object, Kernel].include?(self) || parent == self - super - else - begin + c = Thread.critical + Thread.critical = true + begin + if [Object, Kernel].include?(self) || parent == self + const = super + else begin - ActiveSupport::Dependencies.load_missing_constant self, const_name - rescue NameError - parent.send :const_missing, const_name + begin + const = ActiveSupport::Dependencies.load_missing_constant self, const_name + rescue NameError + const = parent.send :const_missing, const_name + end + rescue NameError => e + # Make sure that the name we are missing is the one that caused the error + parent_qualified_name = ActiveSupport::Dependencies.qualified_name_for parent, const_name + raise unless e.missing_name? parent_qualified_name + qualified_name = ActiveSupport::Dependencies.qualified_name_for self, const_name + raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e) end - rescue NameError => e - # Make sure that the name we are missing is the one that caused the error - parent_qualified_name = ActiveSupport::Dependencies.qualified_name_for parent, const_name - raise unless e.missing_name? parent_qualified_name - qualified_name = ActiveSupport::Dependencies.qualified_name_for self, const_name - raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e) end + rescue + Thread.critical = c + raise end + Thread.critical = c + const end end