Bug 1603123 - API: Querying latest packages returns multiple matches
Summary: API: Querying latest packages returns multiple matches
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: dnf
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: rpm-software-management
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-07-19 09:00 UTC by Lubomír Sedlář
Modified: 2018-07-19 11:42 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-07-19 11:42:26 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

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.


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