Patch #23269

Fix for Error: Unable to autoload constant Redmine::Version when accessing the time report in first request

Added by Holger Just about 1 year ago. Updated 12 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Rails support
Target version:3.2.4

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.

0001-Fully-qualify-the-Version-class-in-Redmine-Helpers-T.patch Magnifier (1.15 KB) Holger Just, 2016-07-07 13:03

Associated revisions

Revision 15645
Added by Jean-Philippe Lang about 1 year ago

Fully qualify the Version class in Redmine::Helpers::TimeReport (#23269).

Patch by Holger Just.

History

#1 Updated by Jean-Philippe Lang about 1 year ago

  • Status changed from New to Resolved
  • Assignee set to Jean-Philippe Lang
  • Target version set to 3.2.4

Committed, thanks.

#2 Updated by Jean-Philippe Lang 12 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF