Bug 1673075 - The base.sack.query().available() example does not seem to work out of box
Summary: The base.sack.query().available() example does not seem to work out of box
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: dnf
Version: 29
Hardware: Unspecified
OS: Unspecified
medium
unspecified
Target Milestone: ---
Assignee: Marek Blaha
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-02-06 15:42 UTC by Jan Pazdziora
Modified: 2019-08-31 01:38 UTC (History)
10 users (show)

Fixed In Version: dnf-4.2.5-4.fc29
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-08-31 01:38:50 UTC


Attachments (Terms of Use)

Description Jan Pazdziora 2019-02-06 15:42:41 UTC
Description of problem:

The page https://dnf.readthedocs.io/en/latest/api_queries.html describes now query() might be used. The first example shows:

q = base.sack.query()
i = q.installed()
i = i.filter(name='pepper')
packages = list(i) # i only gets evaluated here

a = q.available()
a = a.filter(name='pepper')
for pkg in a: # a only gets evaluated here
    print(pkg.name)

and the first part can be made working in standalone script as

#!/usr/bin/python3
import dnf
base = dnf.Base()
base.fill_sack()
q = base.sack.query()
i = q.installed()
for p in i:
        print(p, p.reponame)

I myself would have preferred to have such a standalone example shown but the q.installed() part works well.

However, the q.available() part does not work out of box -- running

#!/usr/bin/python3
import dnf
base = dnf.Base()
base.fill_sack()
q = base.sack.query()
a = q.available()
a = a.filter(name = "zsh")
for p in a:
        print(p, p.reponame)

does not print anything even if running

dnf list zsh

works fine.

It'd be nice to have complete examples, not just snippets without context and without obvious way of making them working.

Version-Release number of selected component (if applicable):

dnf-4.0.9-2.fc29.noarch

How reproducible:

Deterministic.

Steps to Reproduce:
1. Read https://dnf.readthedocs.io/en/latest/api_queries.html.
2. Be happy that there is available() which is documented to
    Return a new query limiting the original query to the not-installed packages, that is packages available from the repositories.
3. Based on the example snippet on that page, create and run script

#!/usr/bin/python3
import dnf
base = dnf.Base()
base.fill_sack()
q = base.sack.query()
a = q.available()
a = a.filter(name = "zsh")
for p in a:
        print(p, p.reponame)


Actual results:

Nothing printed.

Expected results:

The zsh package information printed.

Additional info:

Of course, it's well possible that the example and my approach is correct and the bug is in the dnf code -- in that case the code should be fixed. ;-)

Comment 1 Marek Blaha 2019-02-07 06:09:03 UTC
True, there is `base.read_all_repos()` line missing in the example just before base.fill_sack() line. Without this, dnf is working only with @System repo, so there are no "available" package.
We will update the documentation.

Comment 2 Jan Pazdziora 2019-02-07 08:10:06 UTC
Thanks. Confirming that adding base.read_all_repos() makes the code work:

zsh-5.6.2-3.fc29.x86_64 updates
zsh-5.6.2-1.fc29.x86_64 fedora

Comment 4 Fedora Update System 2019-08-14 07:23:59 UTC
FEDORA-2019-d4b6ede072 has been submitted as an update to Fedora 29. https://bodhi.fedoraproject.org/updates/FEDORA-2019-d4b6ede072

Comment 5 Fedora Update System 2019-08-16 20:12:21 UTC
dnf-4.2.5-4.fc29, dnf-plugins-extras-4.0.4-2.fc29, libdnf-0.31.0-6.fc29 has been pushed to the Fedora 29 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-d4b6ede072

Comment 6 Fedora Update System 2019-08-31 01:38:50 UTC
dnf-4.2.5-4.fc29, dnf-plugins-extras-4.0.4-2.fc29, libdnf-0.31.0-6.fc29 has been pushed to the Fedora 29 stable repository. If problems still persist, please make note of it in this bug report.


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