Bug 1603123

Summary: API: Querying latest packages returns multiple matches
Product: [Fedora] Fedora Reporter: Lubomír Sedlář <lsedlar>
Component: dnfAssignee: rpm-software-management
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: dmach, mblaha, mhatina, packaging-team-maint, rpm-software-management, vmukhame
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-07-19 11:42:26 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Lubomír Sedlář 2018-07-19 09:00:08 UTC
Description of problem:
After calling latest() on the query, if a package is included in multiple repos,  a copy from each repo is still returned.

Version-Release number of selected component (if applicable):
python3-dnf-3.0.3-2.fc29.noarch

How reproducible:
100%

Steps to Reproduce:
1. Create a repo with a single package
2. Run following script:

#!/usr/bin/env python

import logging
import os
import tempfile

---- %< ----
import dnf

REPO = "file://" + os.path.dirname(os.path.abspath(__file__))

logging.basicConfig(level=logging.WARNING)

base = dnf.Base()
base.conf.cachedir = tempfile.mkdtemp()

repo = dnf.repo.Repo('main', base.conf)
repo.baseurl = REPO
repo.enable()
base.repos.add(repo)
repo.priority = 20

repo = dnf.repo.Repo('lookaside', base.conf)
repo.baseurl = REPO
repo.enable()
base.repos.add(repo)
repo.priority = 10

base.fill_sack(load_system_repo=False)
query = base.sack.query().latest()

for pkg in query.filter(name="dummy-basesystem"): # REPLACE NAME
    print("Found %s in %s" % (pkg.name, pkg.repoid))
---- %< ----

Actual results:
With python3-dnf-3.0.3-2.fc29.noarch I'm getting the package in both main and lookaside repo.


Expected results:
With python3-dnf-2.7.5-2.fc27.noarch only the package in lookaside is returned.


Additional info:
If the call to latest() is removed, then both versions return all copies of the package.

Comment 1 Daniel Mach 2018-07-19 11:42:26 UTC
This is expected behavior.
In the past, query().latest() returned only one match and was hiding RPMs with the same NEVRA from different repos.

There was also a bug that query().latest(n) returned n packages.
Now it returns all packages with n latest NEVRAs.

My suggestion is to use either first [0] or last [-1] returned package according what you need to achieve in the program.