Actions
Bug #34509
openAudit report fails with "ActionView::Template::Error: undefined method `each' for nil:NilClass"
Status:
New
Priority:
Normal
Assignee:
-
Category:
Audit Log
Target version:
-
Description
When running the "daily foreman-rake reports:daily" cron job the reports were not being generated.
The cron.log (and running it manually) show errors:
rake aborted! ActionView::Template::Error: undefined method `each' for nil:NilClass /usr/share/foreman/app/views/audit_mailer/summary.html.erb:17:in `block in _a8bd071d84fdc54adfe5da23a38082c6' /usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/relation/delegation.rb:87:in `each' /usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/relation/delegation.rb:87:in `each' /usr/share/foreman/app/views/audit_mailer/summary.html.erb:6:in `_a8bd071d84fdc54adfe5da23a38082c6' /usr/share/gems/gems/actionview-6.0.3.7/lib/action_view/base.rb:274:in `_run' /usr/share/gems/gems/actionview-6.0.3.7/lib/action_view/template.rb:185:in `block in render' /usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/notifications.rb:182:in `instrument' /usr/share/gems/gems/actionview-6.0.3.7/lib/action_view/template.rb:385:in `instrument_render_template' /usr/share/gems/gems/actionview-6.0.3.7/lib/action_view/template.rb:183:in `render' /usr/share/gems/gems/deface-1.5.3/lib/deface/action_view_extensions.rb:43:in `render'
There's a lot more after that, but probably not as relevant. I can provide more if needed.
Looking at the code mentioned in the traceback, I found that there's a case statement in foreman/app/helpers/audits_helper.rb starting on line 89 with two "when" clauses but no "else". When I added an else clause to it the rake task was able to complete successfully.
Here's a diff with the changes I made:
--- /usr/share/foreman/app/helpers/audits_helper.rb 2022-02-23 10:37:51.713526430 -0800 +++ ./audits_helper.rb 2022-02-23 10:41:34.602896704 -0800 @@ -91,6 +91,8 @@ [_("Added %{from} to %{to}") % {:from => from, :to => to}] when AUDIT_REMOVE [_("Removed %{from} to %{to}") % {:from => from, :to => to}] + else + [] end else []
I have no idea if returning [] is the proper thing to do here or what action besides AUDIT_ADD or AUDIT_REMOVE is being encountered.
No data to display
Actions