Description of problem: While generating Host-Registered Content Hosts report template getting error "undefined method `nvra' for nil:NilClass" Version-Release number of selected component (if applicable): Satellite 6.13.0 How reproducible: always Steps to Reproduce: 1. Register hosts to satellite 2. Go to webUI > monitor > Report-templates > click generate in front of "Host-Registered Content Hosts" > select date/time and generate . Actual results: Report not generated and giving error . Expected results: Report should generate and show all registered hosts details Additional info:
Analysis: Old code: ( 6.12 and before ) def host_latest_applicable_rpm_version(host, package) host.applicable_rpms.where(name: package).order(:version_sortable).limit(1).pluck(:nvra).first end New Code: ( > = 6.13 ) def host_latest_applicable_rpm_version(host, package) ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.nvra end Test of new code: irb(main):004:0> host = Host.second => #<Host::Managed id: 2, name: "dhcp130-139.example.com", last_compile: "2023-05-09 09:35:24.000000000 +0000", last_rep... irb(main):007:0> package = 'kernel' => "kernel" irb(main):008:0> ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.nvra Traceback (most recent call last): 2: from lib/tasks/console.rake:5:in `block in <top (required)>' 1: from (irb):8 NoMethodError (undefined method `nvra' for nil:NilClass) irb(main):009:0> ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first => nil irb(main):011:0> ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.try(:nvra) => nil Basically, If the host.applicable_rpms have no results or host.applicable_rpms.where(name: package)).first have no results, we run into this and if we use the try method , that helps to get past the issue So following, fixes the issue: diff --git a/app/lib/katello/concerns/base_template_scope_extensions.rb b/app/lib/katello/concerns/base_template_scope_extensions.rb index 873c7bf..6cfe8f8 100644 --- a/app/lib/katello/concerns/base_template_scope_extensions.rb @@ -161,7 +161,7 @@ module Katello returns String, desc: 'Package version' end def host_latest_applicable_rpm_version(host, package) - ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.nvra + ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.try(:nvra) end apipie :method, 'Loads Pool objects' do
I am guessing this also fixes the issue instead of what I tried in Coment 1 https://github.com/Katello/katello/pull/10497/files#diff-97789298ab25018d9ce64de6b68fa6cfcc0b066e351c4156ebd5d70176022281R182-R186 def host_latest_applicable_rpm_version(host, package) return [] if host.content_facet.nil? applicable = ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)) applicable.present? ? applicable.first.nvra : [] end This change is scheduled to be part of Satellite 6.14 along with the inclusion Installable ERRATA template But perhaps we should consider this or part of the fix for 6.13.z or else many customers could end up hitting this issue when a host would not have any applicable rpms CC'ing Ian from the Katello team
We can use the same code from the "Installable ERRATA template" RFE but we'll need something that only applies to the 6.13 / Katello 4.7 branches.
To complete this issue I'd recommend making a Katello 4.7 issue upstream and then create the PR against the Katello 4.7 branch only. That should ensure that, next time there's a Katello 4.8 release, it'll be marked as a cherry-pick.
Created redmine issue https://projects.theforeman.org/issues/36486 from this bug
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/36486 has been resolved.