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.

Weird classes namespace whith cache_classes = false

#5735

Hi,

I've observed a weird behavior of loading classes with namespace. I have a class that is not in a module:

class RedactionControllers < ActionController::Base
end

I can access it normally:

Loading development environment (Rails 3.0.0)
ruby-1.9.2-p0 > RedactionController 
 => RedactionController

But I should not be able to access it in a namespace:

ruby-1.9.2-p0 > Redaction::RedactionController
 => RedactionController

But, if I change config.cache_classes from false to true (in my development environment), I have the expected behavior:

ruby-1.9.2-p0 > Redaction::RedactionController
NameError: uninitialized constant Redaction::RedactionController

This bug has some consequences. In my case, I have this route:

namespace :redaction do
  root :to => "redaction#index"
end

Everything works well in development (with config.cache_classes = false), but it explodes in production (with config.cache_classes = true):

Routing Error
uninitialized constant Redaction::RedactionController

We should fix this difference between development and production to avoid that developers discover some bugs on the production.

Reported by Bruno Michel · September 29th, 2010 @ 08:45 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Bruno Michel
    Bruno Michel

    I've addded the failing test case.

    September 29th, 2010 @ 09:28 PM

  2. Bruno Michel
  3. Bruno Michel
  4. Bruno Michel
    Bruno Michel

    In my example, Redaction is a module, and the bug is only if the nesting namesapce is a module (not a class). So i've updated my test case to reflect that.

    I've tried to fix this bug, but I can't find how to differentiate A::B from module A; B; end in the autoloading stuff.

    October 2nd, 2010 @ 04:04 PM

  5. David Trasbo
    David Trasbo
    • State changed from new to incomplete
    • Importance changed from to Low

    The patch with the failing test case no longer seems to apply cleanly:

    Applying: Failing test case for #5735
    fatal: corrupt patch at line 23
    Patch failed at 0001 Failing test case for #5735
    When you have resolved this problem run "git am --resolved".
    If you would prefer to skip this patch, instead run "git am --skip".
    To restore the original branch and stop patching run "git am --abort".
    

    Could you please update it, and perhaps provide a fix if you figured it out?

    October 8th, 2010 @ 09:43 AM

  6. Bruno Michel
    Bruno Michel

    I've updated the patch for the failing test case, but I didn't figure how to fix it without breaking others tests. Seems like it's a complex task, that needs a deep comprehension of loading of classes and modules.

    October 10th, 2010 @ 06:44 PM

  7. David Trasbo
    David Trasbo
    • State changed from incomplete to open

    October 10th, 2010 @ 08:29 PM

  8. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • State changed from open to incomplete
    • Tag changed from cache_classes, namespace to cache_classes, namespace, patch

    Please use the "patch" tag when adding a patch to make sure patched tickets end up in the open patches bin. :)

    October 10th, 2010 @ 08:30 PM

  9. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 11th, 2010 @ 02:59 AM

  10. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 11th, 2010 @ 02:59 AM

  11. Bruno Michel
    Bruno Michel

    Jeff: I haven't use the patch tag on purpose, because it's only a failing test case and I haven't figured how to fix it (and even if it's possible to do that).

    October 14th, 2010 @ 08:05 PM

  12. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • State changed from incomplete to open
    • Tag set to cache_classes, namespace

    Bruno: I guess I didn't see that was a failing-test-patch. I have no clue why I marked it as incomplete either. My bad, sorry.

    October 14th, 2010 @ 08:29 PM

  13. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:32 AM

  14. Santiago Pastorino
    Santiago Pastorino

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:47 PM

  15. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:47 PM

  16. Bruno Michel
  17. Bruno Michel
    Bruno Michel
    • State changed from stale to open

    I've update the failing test case for 3-0-stable. I don't have any idea on how to fix it but I hope someone else will be able to help me on that.

    [state:open]

    February 2nd, 2011 @ 10:13 PM

  18. rails
    rails

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    May 3rd, 2011 @ 01:00 AM

  19. rails
    rails
    • State changed from open to stale

    May 3rd, 2011 @ 01:00 AM