This project is archived and is in readonly mode.

#4731 ✓stale
Serge Balyuk

[PATCH] fix ActiveSupport::Dependencies removes properly loaded classes nested in autoloaded modules

Reported by Serge Balyuk | May 30th, 2010 @ 04:39 PM

I've discovered this under the following conditions:

  • ApplicationController has helper :all call (it requires all helper files right away)
  • some helpers are nested into Admin module, that module is autoloaded by directory name
  • one of helper files contains either syntax error or requires missing file, so that either LoadError or SyntaxError gets thrown.

Here, application_controller.rb can't be loaded because one of it's dependencies fails. This situation is handled by new_constants_in and partially loaded constants are removed. Admin autoloaded module is considered as such and gets removed along with all its nested modules, so all Admin::* helpers get removed.

The problem is that although helpers where removed, their paths still exist in loaded set. So subsequent load of application_controller.rb (for rescue handling) throws another exception which can be misleading. It blames the first Admin::* helper with a message like "Expected app/helper/admin/some_helper.rb to define Admin::SomeHelper"

Please find proposed fix attached. It changes logic so that autoloaded modules are not removed on load failure recovery. I hope that makes sense as such modules are created by dependencies mechanism and should not have partially loaded state.

Also, condition in load_missing_constant is checking file_path with .rb extension against loaded set which holds paths without those. I think that does not cause any problems because require_or_load contains another check which is correct. I've changed that line, however.

The other test case and fix is also related to autoloaded modules handling. If some namespace spans across reloadable and load_once_paths, and module was created by a directory name from reloadable set, it gets removed on reload despite the fact that it holds classes from load_once_paths.

Hope that makes some sense. I wonder if these changes can produce any undesired side effects. All existing tests pass however.

Thanks
Serge

Comments and changes to this ticket

  • Serge Balyuk

    Serge Balyuk June 1st, 2010 @ 08:13 AM

    • Title changed from “[PAtCH] fix ActiveSupport::Dependencies removes properly loaded classes nested in autoloaded modules” to “[PATCH] fix ActiveSupport::Dependencies removes properly loaded classes nested in autoloaded modules”
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:51 PM

    • State changed from “new” to “open”

    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

    Santiago Pastorino February 2nd, 2011 @ 04:51 PM

    • State changed from “open” to “stale”
  • bingbing

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>

People watching this ticket

Attachments

Referenced by

Pages