Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4638 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

[PATCH] [TINY] Unloaded namespaced models in session cause ActiveController::Base#stale_session_check! to go into infinite retry loop

Reported by: dfelstead@site5.com Assigned to: ulysses
Priority: normal Milestone:
Component: ActionPack Version: 1.1.1
Severity: critical Keywords:
Cc: agreenfield@site5.com

Description (Last modified by ulysses)

If an unloaded (not specifically 'require'd) model is stored in session (an example would be an instance of Client::Contact), when it is reloaded, the following code is called:

      def stale_session_check!
        yield
      rescue ArgumentError => argument_error
        if argument_error.message =~ %r{undefined class/module (\w+)}
          begin
            STDERR.puts "CHECKING FOR #{$1}"
            Module.const_missing($1)
          rescue LoadError, NameError => const_error
            raise ActionController::SessionRestoreError, <<-end_msg
Session contains objects whose class definition isn\'t available.
Remember to require the classes for all objects kept in the session.
(Original exception: #{const_error.message} [#{const_error.class}])
end_msg
          end
          retry
        else
          raise
        end
      end

The problem is in the regular expression %r{undefined class/module (\w+)} and subsequent 'Module.const_missing($1)' call - if the error is "undefined class/module Client::Contact", then $1 will be 'Client' rather than 'Client::Contact', and thus the 'retry' call is triggered ad infinitum.

The fix is simply to change the regex to %r{undefined class/module ([\w:]+)}, which allows the loader to load the appropriate class or fail gracefully.

I will submit a test to reproduce this error and a patch to fix it shortly.

Attachments

patch_for_4638.diff (494 bytes) - added by dfelstead@site5.com on 04/07/06 11:37:56.
Patch to fix issue #4638

Change History

04/07/06 11:37:56 changed by dfelstead@site5.com

  • attachment patch_for_4638.diff added.

Patch to fix issue #4638

04/07/06 11:42:00 changed by dfelstead@site5.com

  • summary changed from Unloaded namespaced models in session cause ActiveController::Base#stale_session_check! to go into infinite retry loop to [PATCH] Unloaded namespaced models in session cause ActiveController::Base#stale_session_check! to go into infinite retry loop.

I've attached the patch that fixes this issue - I'll continue to try to fabricate a test case for it, though it turns out to be more difficult than I anticipated, as I have to pass the requests through the CGI processing calls.

As it turns out, none of the current tests touch the branch of code we're looking at, so it is pretty much uncovered by test code - it could probably be tested via integration tests, but I haven't seen any of these in the core code, so am not sure if they are supported? Any advice would be good, otherwise, seeing it's just a single liner and an "obvious" patch, it might be acceptable as is.

05/22/06 00:17:48 changed by anonymous

  • summary changed from [PATCH] Unloaded namespaced models in session cause ActiveController::Base#stale_session_check! to go into infinite retry loop to [PATCH] [TINY] Unloaded namespaced models in session cause ActiveController::Base#stale_session_check! to go into infinite retry loop.

09/04/06 20:50:44 changed by david

  • owner changed from David to nseckar@gmail.com.

09/07/06 17:30:22 changed by ulysses

  • description changed.

(follow-up: ↓ 6 ) 09/20/06 17:46:59 changed by ulysses

  • status changed from new to closed.
  • resolution set to fixed.

(In [5152]) Update CGI process to allow sessions to contain namespaced models. Closes #4638.

(in reply to: ↑ 5 ) 10/01/06 17:56:10 changed by jaylev

This seems to still be broken, at least for non-model classes. I have a class Hark::Session that is defined in lib/hark/session.rb. When I add it to session[], I start seeing the above error. Oddly, I see it even if I explicitly require it in application.rb, but I assume that's my bug somewhere. Leaving closed to defer to core's judgement.

10/01/06 22:50:16 changed by jaylev

  • status changed from closed to reopened.
  • resolution deleted.

OK, the problem seems to be on line 225 of dependencies.rb; you can't call Object::const_defined?("SomeModule::SomeClass"), or you get a NameError, which silently disappears somehow. I'm not qualified to recommend a fix, let alone patch it.

New ticket, or stay here?

10/04/06 21:04:07 changed by ulysses

  • status changed from reopened to closed.
  • resolution set to fixed.

I'm up for a new ticket; using "references #4638" allows us to go back in history...

See #6348.