# ActiveSupport "is not missing constant" errors

**URL:** <https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314>\
**Category:** Ruby\
**Created:** [June 15, 2009, 9:28pm UTC](https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314 "2009-06-15T21:28:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 15, 2009, 9:28pm UTC](https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314/1 "2009-06-15T21:28:22Z")

</div>

I’ve gone spelunking through ActiveRecord’s dependencies.rb until my  
eyes  
bleed, and I’m still yet to understand what causes these errors and how  
can  
they can be prevented.

As far as I can tell, ActiveSupport’s const\_missing callback is  
triggered.  
ActiveSupport then attempts automatic code loading, only to discover  
that  
the constant is, in fact, already defined.

I am specifically encountering this problem trying to use a  
dependency-resolving code loader:

[http://github.com/tarcieri/require\_all/tree/master](http://github.com/tarcieri/require_all/tree/master)

I’ve encountered this problem using Merb’s code loader as well (albeit  
outside of Merb). Merb’s code loader works in the same way so I’m  
wondering  
if this issue comes up with Merb as well.

In the latest case, the code loads in through the code loader correctly,  
however when it tried to access a particular constant in a method body,  
the  
error is generated, even though the class has been loaded. This doesn’t  
even happen consistently either: it is happening on one of my coworker’s  
computers (and only his computer, even though his setup is virtually  
identical to our CI server). Also, it occurs only when the full Rails  
environment is loaded, not in unit tests. _sigh_

This has been a perpetual thorn in my side for over a year. I really  
have  
to wonder?

1. What does this “error” really mean?
2. Why is it an error?
3. Why can’t ActiveSupport handle it internally?
4. What am I expected to do in order to fix it?

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 18, 2009, 5:22am UTC](https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314/2 "2009-06-18T05:22:06Z")

</div>

_tumbleweeds_

Okay, different question… does anyone know who specifically I can  
contact  
about this question? Is there a more appropriate mailing list I should  
be  
asking this on?

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 18, 2009, 7:28am UTC](https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314/3 "2009-06-18T07:28:56Z")

</div>

Tony A. wrote:

> _tumbleweeds_
> 
> Okay, different question… does anyone know who specifically I can contact  
> about this question? Is there a more appropriate mailing list I should be  
> asking this on?

Yes, you should be asking this question on the rails list. But for what  
it’s worth, I’ve had that kind of problem before when the rails  
auto-loading magic is triggered in threads; i.e. it’s not thread-safe.

Daniel

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 18, 2009, 8:01am UTC](https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314/4 "2009-06-18T08:01:47Z")

</div>

On Wed, Jun 17, 2009 at 11:54 PM, Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> But for what it’s worth, I’ve had that kind of problem before when the
> 
> > rails auto-loading magic is triggered in threads; i.e. it’s not thread-safe.
> 
> Why not?

And more to the point: how can you implement this sort of automatic code  
loading so it works alongside ActiveSupport?

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 18, 2009, 8:00am UTC](https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314/5 "2009-06-18T08:00:36Z")

</div>

On Wed, Jun 17, 2009 at 11:28 PM, Daniel DeLorme [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Yes, you should be asking this question on the rails list.

The idea that Rails core doesn’t read ruby-talk confounds me.

> But for what it’s worth, I’ve had that kind of problem before when the  
> rails auto-loading magic is triggered in threads; i.e. it’s not thread-safe.

Why not?

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 18, 2009, 7:39pm UTC](https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314/6 "2009-06-18T19:39:39Z")

</div>

On Thu, Jun 18, 2009 at 7:46 AM, Rick DeNatale  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> I’m not sure I know how. Even if autoload were thread safe, I think  
> you’re approach, which if I remember it correctly, of trying to  
> explicitly require files until things work, is prone to confusing or  
> being confused by code using autoload.

Well, it’s not “my approach” per se, it’s the same approach used by Merb

So I suppose I’m curious why more people don’t experience this problem  
when  
using ActiveRecord/ActiveSupport in conjunction with Merb (or for that  
matter, Rails 3.0)

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 18, 2009, 3:47pm UTC](https://www.ruby-forum.com/t/activesupport-is-not-missing-constant-errors/170314/7 "2009-06-18T15:47:41Z")

</div>

On Thu, Jun 18, 2009 at 1:57 AM, Tony A.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Wed, Jun 17, 2009 at 11:54 PM, Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > But for what it’s worth, I’ve had that kind of problem before when the
> > 
> > > rails auto-loading magic is triggered in threads; i.e. it’s not thread-safe.
> > 
> > Why not?

Probably because autoload in Ruby (which ActiveSupport now uses to  
implement loading missing constants) isn’t and it appears to be  
difficult to make it so:

[http://redmine.ruby-lang.org/issues/show/921](http://redmine.ruby-lang.org/issues/show/921)

> And more to the point: how can you implement this sort of automatic code  
> loading so it works alongside ActiveSupport?

I’m not sure I know how. Even if autoload were thread safe, I think  
you’re approach, which if I remember it correctly, of trying to  
explicitly require files until things work, is prone to confusing or  
being confused by code using autoload.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)
