Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord: nested "include" hints fail if record classes are in modules

#260

ActiveRecord 2.0.2 can't load records whose classes are in modules when using nested "include"s.

e.g.

@edition = Edition.find_by_id(edition_id, {:include => {:published_item => :user}})

gives an error:

C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:266:in

`load_missing_constant': uninitialized constant PublishedItem (NameError)

This appears to be because "constantize" is called on the string "PublishedItem", which isn't a constant, although "YuduLibrary::Model::PublishedItem" is.

I've attached a monkey patch which I'm currently using to work around the problem.

I would submit a proper patch to fix the issue, but I can't get the ActiveRecord unit tests to run on my machine (win32).

Reported by Rich Bradley · May 27th, 2008 @ 12:17 PM

State: committed
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. josh
    josh
    • State changed from new to stale
    • Tag set to activerecord

    Closing this ticket as stale. If this is still an issue for you, feel free to reopen this ticket or create a new one with an updated description. Remember those unit tests too ;)

    July 17th, 2008 @ 01:59 AM

  2. Rich Bradley
  3. Rich Bradley
    Rich Bradley

    Here's a patch, which fixes the issue, and adds a new unit test to demonstrate the problem.

    This bug is harder to reproduce on HEAD than on 2.0.2, because it only occurs in the "join" eager load model, which has been replaced by a sequential eager load model as per: http://dev.rubyonrails.org/ticke...

    Let me know if you need anything else.

    July 28th, 2008 @ 05:24 PM

  4. Rich Bradley
    Rich Bradley

    How do I mark the ticket as no longer stale?

    July 28th, 2008 @ 05:26 PM

  5. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from activerecord to activerecord, bugmash

    August 3rd, 2009 @ 03:02 PM

  6. Rich Bradley
    Rich Bradley

    This bug is still present, one year after I submitted a patch with unit tests :-(

    It probably crops up in other places -- have a search for ".class_name.constantize" -- I think that all of these ought to use ".klass" instead. There's at least one other instance in lib/active_record/associations.rb

    Mike, thanks for tagging this "bugmash". Maybe it'll get looked at?

    I think all this needs is committing? It doesn't seem to fit any of 1-4 at http://weblog.rubyonrails.org/2009/7/28/rails-bugmash

    (Well, maybe it fails '3' -- "a patch that applies cleanly to the current Rails source"; I haven't checked if the patch still applies cleanly to HEAD -- it's been a while since I wrote it :-)

    If anyone watching this ticket has any advice on what I could have done differently here to get this committed back in Jul 2008, I'd love to hear it.

    I think I followed all the steps at http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-people...

    .. something's just occurred to me: I've been waiting for someone with "commit rights" to commit this. Is that not how it works on Rails?

    August 3rd, 2009 @ 05:04 PM

  7. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from stale to open

    Rich - Yes, flagging this for a look by someone during the upcoming BugMash (http://wiki.railsbridge.org/projects/railsbridge/wiki/BugMash). We're going to make a concerted effort to clean up some of the stuff that's been hanging around for a long while.

    If you wanted to participate yourself, that'd be great. Otherwise with any luck someone will volunteer to look up.

    And yes, in Rails it needs someone with commit rights to commit. We'll have committers involved.

    August 3rd, 2009 @ 07:04 PM

  8. Dmitry Ratnikov
    Dmitry Ratnikov

    +1 Seems to apply cleanly to both master and 2-3-stable.

    I have extended the patch to fix the class_name.constantize call in _ids= assignment. I have also attached a test to test it, but perhaps someone could take a look at it and make it a bit neater?

    August 9th, 2009 @ 06:53 AM

  9. Dmitry Ratnikov
    Dmitry Ratnikov

    For some reason I fail to update the ticket with the attacked patch, so I put it on drop.io for now: http://drop.io/urxdaxz If someone has better luck attaching things to LH, please do. :)

    -- D

    August 9th, 2009 @ 07:00 AM

  10. Jeremy Kemper
    Jeremy Kemper
    • Assigned user set to Jeremy Kemper
    • Milestone set to 2.3.4

    Rich - sorry this lingered here, incorrectly stale. Thanks BugMash for the archaeology exercise.

    August 9th, 2009 @ 07:26 AM

  11. Gabe da Silveira
    Gabe da Silveira

    Testing to see if I can upload Dmitry's patch for him:

    August 9th, 2009 @ 08:12 AM

  12. Jeremy Kemper
    Jeremy Kemper

    Dmitry - good find on the _ids= assignment. Could you rebase and update the test? I see it can raise an exception, but the test has no assertions.

    August 9th, 2009 @ 08:30 AM

  13. Repository
  14. Repository
  15. Dmitry Ratnikov
    Dmitry Ratnikov

    Here's an updated patch.

    I made the tests actually fail rather than blow up.
    Also, I had to resort to removing constants possibly defined by requiring models/company.rb This allows the test to fail when run as test-suite.

    August 9th, 2009 @ 09:56 AM

  16. Jeremy Kemper
    Jeremy Kemper
    • State changed from committed to open

    Thanks! Needs rebase against Rich's commit.

    August 9th, 2009 @ 10:00 AM

  17. Dmitry Ratnikov
  18. Repository
    Repository
    • State changed from open to committed

    August 9th, 2009 @ 10:52 AM

  19. Repository
  20. CancelProfileIsBroken
    CancelProfileIsBroken
    • Assigned user cleared.
    • Tag changed from activerecord, bugmash to activerecord
    • Milestone cleared.

    August 9th, 2009 @ 11:18 AM

  21. Rich Bradley