ActiveSupport "is not missing constant" errors

Discussion in 'Ruby' started by Tony Arcieri, Jun 15, 2009.

  1. Tony Arcieri

    Tony Arcieri Guest

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

    --
    Tony Arcieri
    medioh.com
     
    Tony Arcieri, Jun 15, 2009
    #1
    1. Advertising

  2. Tony Arcieri

    Tony Arcieri Guest

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

    On Mon, Jun 15, 2009 at 1:27 PM, Tony Arcieri <> 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, Jun 18, 2009
    #2
    1. Advertising

  3. 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
     
    Daniel DeLorme, Jun 18, 2009
    #3
  4. Tony Arcieri

    Tony Arcieri Guest

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

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

    --
    Tony Arcieri
     
    Tony Arcieri, Jun 18, 2009
    #4
  5. Tony Arcieri

    Tony Arcieri Guest

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

    On Wed, Jun 17, 2009 at 11:28 PM, Daniel DeLorme <> 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?

    --
    Tony Arcieri
     
    Tony Arcieri, Jun 18, 2009
    #5
  6. On Thu, Jun 18, 2009 at 1:57 AM, Tony Arcieri<> wrote:
    > On Wed, Jun 17, 2009 at 11:54 PM, Tony Arcieri <> 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

    > 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
     
    Rick DeNatale, Jun 18, 2009
    #6
  7. Tony Arcieri

    Tony Arcieri Guest

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

    On Thu, Jun 18, 2009 at 7:46 AM, Rick DeNatale <>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)

    --
    Tony Arcieri
    medioh.com
     
    Tony Arcieri, Jun 18, 2009
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. han
    Replies:
    0
    Views:
    222
  2. john peter
    Replies:
    3
    Views:
    294
    Logan Capaldo
    Mar 31, 2006
  3. Trans
    Replies:
    0
    Views:
    131
    Trans
    Sep 12, 2006
  4. Tim Bray
    Replies:
    0
    Views:
    105
    Tim Bray
    Oct 13, 2006
  5. nrolland
    Replies:
    1
    Views:
    107
    George Ogata
    Dec 4, 2006
Loading...

Share This Page