ActiveSupport "is not missing constant" errors

T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

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

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

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

Daniel DeLorme

Tony said:
*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
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

But for what it's worth, I've had that kind of problem before when the

Why not?

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

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

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

Rick DeNatale

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.



--
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
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top