Defect #3705
closedCustom Values with a nil value cause HTTP error 500
0%
Description
I recently upgraded my Redmine installation from r2264 to r2835. The upgrade and database migration went without a hitch.
However, most - but not all - of my project pages stopped working. The log states:
bc. ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.empty?) on line #12 of app/views/projects/show.rhtml:
9: <%= @subprojects.collect{|p| link_to(h(p), :action => 'show', :id => p)}.join(", ") ></li>
10: < end >
11: < @project.custom_values.each do |custom_value| >
12: < if !custom_value.value.empty? >
13: <li><= custom_value.custom_field.name%>: <%=h show_value(custom_value) ></li>
14: < end >
15: < end %>
Digging into my data it appears that all the Projects whose page have stopped working have a bunch of CustomFields with a value of nil:
bc. >> Project.first.custom_values
=> [#<CustomValue id: 234, customized_type: "Project", customized_id: 1, custom_field_id: 4, value: nil>, #<CustomValue id: 235, customized_type: "Project", customized_id: 1, custom_field_id: 5, value: nil>]
Both of those custom fields appear to have been added by the Redmine Hoptoad Server plugin at http://github.com/yeah/redmine_hoptoad_server/tree/master.
Anyways, seeing as there are no validations in RedMine on CustomValue preventing nil-values from being stored in the database, the projects/show.rhtml view is making unsafe assumptions. The attached patch adds a safeguard for the assumption.
The patch also fixes the issue reported in http://www.redmine.org/boards/2/topics/5872, which is basically the same issue as this.
Files
Updated by Jakob Skjerning over 15 years ago
If you, as a Redmine user, want to work around this issue, the following method appears to be working:
1. Go to your Project administration area under Administration > Projects
2. Visit each project that has the above issue.
3. Click "Save".
This should fix the above issue (by replacing the nil-values with empty strings).
Updated by Jean-Philippe Lang over 15 years ago
- Status changed from New to Resolved
- Target version set to 0.8.6
- Resolution set to Fixed
Fixed in r2894. Thanks.
Updated by Jean-Philippe Lang about 15 years ago
- Status changed from Resolved to Closed
Merged in 0.8-stable in r2996.