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.