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:
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?
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?
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.
On Thu, Jun 18, 2009 at 7:46 AM, Rick DeNatale [email protected]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)
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:
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.