Defect #42192
openProject settings members tab may raise ArgumentError if orphaned member records exist
0%
Description
Hi,
after upgrading to 6.0.2, trying to open some project's settings cause http 500 error.
Some projects settings page opens normally, and there seems to be no visible differences between those opening, and those giving this error.
On 5.xx (and prior) versions every project open normally.
This might be related to this change on version 6.0.0
4. Icons have been replaced with SVG icons provided by Tabler (#23980):
Log:
I, [2025-01-20T11:24:11.137017 #1] INFO -- : Completed 500 Internal Server Error in 484ms (ActiveRecord: 296.1ms (24 queries, 0 cached) | GC: 3.3ms) F, [2025-01-20T11:24:11.137989 #1] FATAL -- : ActionView::Template::Error (First argument has to be a Principal, was nil): Causes: ArgumentError (First argument has to be a Principal, was nil) 20: <% next if member.new_record? %> 21: <tr id="member-<%= member.id %>" class="member"> 22: <td class="name icon icon-<%= member.principal.class.name.downcase %>"> 23: <%= principal_icon(member.principal) %> 24: <%= link_to_user member.principal %> 25: </td> 26: <td class="roles"> app/helpers/icons_helper.rb:49:in `principal_icon' app/views/projects/settings/_members.html.erb:23 app/views/projects/settings/_members.html.erb:19:in `each' app/views/projects/settings/_members.html.erb:19 app/views/common/_tabs.html.erb:21 app/views/common/_tabs.html.erb:20:in `each' app/views/common/_tabs.html.erb:20 app/helpers/application_helper.rb:525:in `render_tabs' app/views/projects/settings.html.erb:3 lib/redmine/sudo_mode.rb:78:in `sudo_mode'
Files
Updated by Go MAEDA 6 days ago
- Status changed from New to Needs feedback
The issue is likely caused by an inconsistency between the members
table and the users
table. Specifically, it occurs when there is no corresponding record in the users
table for the user_id
foreign key in the members
table. This situation can happen, for example, if records in the users
table are manually deleted using an SQL DELETE
statement.
As a temporary fix, please open the Redmine source code file app/helpers/icons_helper.rb
and add return if principal.nil?
right after the line def principal_icon(principal, **options)
. Then, restart the Redmine application (or the web server) and check if the issue is resolved.
diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb
index 99006308e..9a39c0d47 100644
--- a/app/helpers/icons_helper.rb
+++ b/app/helpers/icons_helper.rb
@@ -46,6 +46,7 @@ module IconsHelper
end
def principal_icon(principal, **options)
+ return if principal.nil?
raise ArgumentError, "First argument has to be a Principal, was #{principal.inspect}" unless principal.is_a?(Principal)
principal_class = principal.class.name.downcase
Updated by Mika Seppälä 6 days ago
Hi!
and many thanks for the quick response, that resolved the issue!
br,
-mika
Updated by Go MAEDA 6 days ago
- File 42192.patch 42192.patch added
- Subject changed from Opening project settings cause http 500 error to Project settings members tab may raise ArgumentError if orphaned member records exist
- Category changed from Issues to Project settings
- Status changed from Needs feedback to Confirmed
- Target version set to 6.0.4
Thank you for your feedback. I will include this fix in 6.0.4.
Updated by Mika Seppälä 5 days ago
And your assesment of the root cause was correct too. We had rows in members table which pointed to non-existent users.
br,
-mika
Updated by Holger Just 5 days ago
Rather than trying to workaround the deliberate exception in the principal_icon
helper, a different option may be handle this condition in the callsite instead. This could look as follows:
diff --git a/app/views/projects/settings/_members.html.erb b/app/views/projects/settings/_members.html.erb
index abe4ed9969..0514baca0e 100644
--- a/app/views/projects/settings/_members.html.erb
+++ b/app/views/projects/settings/_members.html.erb
@@ -21,8 +21,10 @@
<tr id="member-<%= member.id %>" class="member">
<td class="name">
<span class="icon">
- <%= principal_icon(member.principal) %>
- <%= link_to_user member.principal %>
+ <% if member.principal %>
+ <%= principal_icon(member.principal) %>
+ <%= link_to_user member.principal %>
+ <% end %>
</span>
</td>
<td class="roles">
If desired, this could be amended to render an explanatory text in the view, e.g. "deleted user" or something similar.