Report Template - Get current package and available package version

After putting the below report together to try and generate a report for packages that will be updated and what version they will be updated too i find that the new latest applicable is just the next version in the list, not actually the latest one

Current output
zabbix-agent2 zabbix-agent2-5.4.1-1.sles15.x86_64 zabbix-agent2-5.4.1-1.sles15.x86_64 zabbix-agent2-5.4.2-1.sles15.x86_64

Expected outcome:
the latest zabbix-agent2 should be zabbix-agent2-5.4.4-1.sles15.x86_64 as thats the latest available if i go to Content → Packages → Search zabbix-agent2 it shows that applicable for the servers

Foreman and Proxy versions:

Smart Proxy: 2.5.1
Foreman and Proxy plugin versions:

Distribution and version:
CentOS 7

Other relevant data:
Sample report

name: Host - All Installed Packages
snippet: false

  • name: Hosts filter
    required: false
    input_type: user
    description: Limit the report only on hosts found by this search query. Keep empty
    for report on all available hosts.
    advanced: false
    value_type: search
    resource_type: Host
    hidden_value: false
    model: ReportTemplate
    <%- load_hosts(search: input(‘Hosts filter’)).each_record do |host| -%>
    <%- host.installed_packages.each do |pkg| -%>
    <%- report_row(
    ‘Package Name’:,
    ‘Package NVRA’: pkg.nvra,
    ‘Package NVREA’: pkg.nvrea,
    ‘Package New NVRA’: host_latest_applicable_rpm_version(host,
    <%- end -%>
    <%- end -%>
    <%= report_render -%>

You seem to be hitting the same issue we’ve seen with other report -, the issue seems to be the host_latest_applicable_rpm_version does not work well, more specifically, order(:version_sortable) does not seem to guarantee the right order. My content area knowledge ends here, perhpas @Justin_Sherrill would know who could take a look at fixing this.

I think changing order(:version_sortable) to order(:name, evr: ‘desc’) should fix it. We now use the evr column to do sorting in a better manner. We should probably just remove the :version_sortable column altogether

Thanks for the info is that going to be in one of the later releases?? I can always modify this is a test environment and see what happens


So i updated “/opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.1.0/app/lib/katello/concerns/base_template_scope_extensions.rb” with the new order as mentioned and ran the report and the output seems to be as expected ill need to review but on first look the output is showing the right next available version in the CV