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.

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

#4731

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

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

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

Activity

  1. Serge Balyuk
    Serge Balyuk
    • 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

    June 1st, 2010 @ 08:13 AM

  2. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:51 PM

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

    February 2nd, 2011 @ 04:51 PM

  4. bingbing