Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2196540 - "Host-Registered Content Hosts" Report gives error while generating - undefined method `nvra' for nil:NilClass
Summary: "Host-Registered Content Hosts" Report gives error while generating - undefin...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Reporting
Version: 6.13.0
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: 6.14.0
Assignee: Samir Jha
QA Contact: Lucy Fu
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-05-09 12:43 UTC by vivek singh
Modified: 2023-11-08 14:19 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2218660 (view as bug list)
Environment:
Last Closed: 2023-11-08 14:19:23 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 36486 0 High Closed "Host-Registered Content Hosts" Report gives error while generating - undefined method `nvra' for nil:NilClass 2023-06-12 13:28:37 UTC
Red Hat Issue Tracker SAT-17630 0 None None None 2023-05-11 14:23:49 UTC
Red Hat Knowledge Base (Solution) 7011854 0 None None None 2023-05-09 15:15:17 UTC
Red Hat Product Errata RHSA-2023:6818 0 None None None 2023-11-08 14:19:39 UTC

Description vivek singh 2023-05-09 12:43:05 UTC
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:

Comment 1 Sayan Das 2023-05-09 12:45:38 UTC
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

Comment 2 Sayan Das 2023-05-09 12:53:37 UTC
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

Comment 3 Ian Ballou 2023-05-09 13:44:51 UTC
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.

Comment 4 Ian Ballou 2023-05-09 13:57:26 UTC
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.

Comment 5 Samir Jha 2023-06-07 16:17:38 UTC
Created redmine issue https://projects.theforeman.org/issues/36486 from this bug

Comment 6 Bryan Kearney 2023-06-12 16:03:11 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/36486 has been resolved.

Comment 12 errata-xmlrpc 2023-11-08 14:19:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: Satellite 6.14 security and bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2023:6818


Note You need to log in before you can comment on or make changes to this bug.