ActiveSupport "is not missing constant" errors

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

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?

···

--
Tony Arcieri
medioh.com

*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?

···

On Mon, Jun 15, 2009 at 1:27 PM, Tony Arcieri <tony@medioh.com> wrote:

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

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?

--
Tony Arcieri
medioh.com

Tony Arcieri 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

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?

···

On Wed, Jun 17, 2009 at 11:28 PM, Daniel DeLorme <dan-ml@dan42.com> wrote:

--
Tony Arcieri

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

···

On Wed, Jun 17, 2009 at 11:54 PM, Tony Arcieri <tony@medioh.com> 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?

--
Tony Arcieri

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

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.

···

On Thu, Jun 18, 2009 at 1:57 AM, Tony Arcieri<tony@medioh.com> wrote:

On Wed, Jun 17, 2009 at 11:54 PM, Tony Arcieri <tony@medioh.com> wrote:

--
Rick DeNatale

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

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)

···

On Thu, Jun 18, 2009 at 7:46 AM, Rick DeNatale <rick.denatale@gmail.com>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.

--
Tony Arcieri
medioh.com