Patch #23269
closedFix for Error: Unable to autoload constant Redmine::Version when accessing the time report in first request
0%
Description
When starting up Redmine in development mode and accessing the /time_entries/report page on the first request, Redmine in at least versions 3.3 and trunk fails to properly autoload the Version
class.
The full error is:
Unable to autoload constant Redmine::Version, expected lib/redmine/version.rb to define it activesupport (4.2.6) lib/active_support/dependencies.rb:495:in `load_missing_constant' activesupport (4.2.6) lib/active_support/dependencies.rb:184:in `const_missing' activesupport (4.2.6) lib/active_support/dependencies.rb:526:in `load_missing_constant' activesupport (4.2.6) lib/active_support/dependencies.rb:184:in `const_missing' activesupport (4.2.6) lib/active_support/dependencies.rb:526:in `load_missing_constant' activesupport (4.2.6) lib/active_support/dependencies.rb:184:in `const_missing' lib/redmine/helpers/time_report.rb:111:in `load_available_criteria' lib/redmine/helpers/time_report.rb:39:in `available_criteria' app/views/timelog/report.html.erb:23:in `block in _app_views_timelog_report_html_erb___3330057872428091759_70181945143200'
The reason for this is that the lookup happens inside the class Redmine::Helpers::TimeReport
and the Version
model class is not loaded yet. Thus, the Rails autoloader tries to load the class and navigates up the module chain. It finds a file matching the naming conventions in lib/redmine/version.rb
which would match the expected module/class Redmine::Version
which in turn would have precedence before ::Version
in the lookup chain.
Since lib/redmine/version.rb
does not define Redmine::Version
, the error occurs. A fix to this is to fully qualify the class on lookup to give the autoloader a hint where to look at. The attached patch fixes this.
Note that this issue doesn't seem to occur in production mode.
Files