This project is archived and is in readonly mode.
Weird classes namespace whith cache_classes = false
Reported by Bruno Michel | September 29th, 2010 @ 08:45 PM
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.
Comments and changes to this ticket
-
Bruno Michel October 1st, 2010 @ 11:32 AM
For the record, this bug seems related to https://rails.lighthouseapp.com/projects/8994/tickets/5383-as-depen...
-
Bruno Michel October 2nd, 2010 @ 04:04 PM
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
frommodule A; B; end
in the autoloading stuff. -
David Trasbo October 8th, 2010 @ 09:43 AM
- 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?
-
Bruno Michel October 10th, 2010 @ 06:44 PM
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.
-
David Trasbo October 10th, 2010 @ 08:29 PM
- State changed from incomplete to open
-
Jeff Kreeftmeijer October 10th, 2010 @ 08:30 PM
- 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. :)
-
Bruno Michel October 14th, 2010 @ 08:05 PM
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).
-
Jeff Kreeftmeijer October 14th, 2010 @ 08:29 PM
- 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.
-
Santiago Pastorino February 2nd, 2011 @ 04:47 PM
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.
-
Santiago Pastorino February 2nd, 2011 @ 04:47 PM
- State changed from open to stale
-
Bruno Michel February 2nd, 2011 @ 10:11 PM
- no changes were found...
-
Bruno Michel February 2nd, 2011 @ 10:13 PM
- 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]
-
rails May 3rd, 2011 @ 01:00 AM
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.
-
rails May 3rd, 2011 @ 01:00 AM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>