Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python bindings for query.filter_<>() behaves strangely #1086

Closed
j-mracek opened this issue Dec 12, 2023 · 8 comments
Closed

Python bindings for query.filter_<>() behaves strangely #1086

j-mracek opened this issue Dec 12, 2023 · 8 comments
Assignees
Labels
Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take
Milestone

Comments

@j-mracek
Copy link
Contributor

Following code provides incorrect results - empty query

        for require in pkg.get_requires():
            query1 = libdnf.rpm.PackageQuery(query)
            query1.filter_provides([str(require)])
        for require in pkg.get_requires():
            query1 = libdnf.rpm.PackageQuery(query)
            query1.filter_provides(str(require))
            query1 = libdnf.rpm.PackageQuery(query)
            query1.filter_provides("dnf")
@j-mracek j-mracek self-assigned this Dec 12, 2023
@github-project-automation github-project-automation bot moved this to Backlog in DNF team Dec 12, 2023
@jan-kolarik jan-kolarik added Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take labels Dec 12, 2023
@j-mracek
Copy link
Contributor Author

j-mracek commented Dec 12, 2023

First problem
str(require) does return class instance description and not string representing reldep. The code requires to call require.to_string() to get required result.

@gotmax23
Copy link
Contributor

gotmax23 commented Dec 12, 2023

Right, libdnf5.rpm.Reldep does not implement __str__(), so calling str() on it just returns the repr.

For the first two examples, you can call query.filter_provides(require) or just pass the ReldepList returned by pkg.get_requires() directly to .filter_provides() without looping. filter_provides() accepts Reldep and ReldepList objects and lists of strings.

For the third one, query1.filter_provides(["dnf"]) should work. The old hawkey.Query.filter(...) API used to accept plain strings in addition to lists of strings, but libdnf5 apparently does not.

I guess the two issues here are implementing the str protocol for Reldep objects and potentially supporting regular strings in addition to ists of strings for these methods.

@j-mracek
Copy link
Contributor Author

I create the first PR that resolves the issue partially - #1092.

Remaining problem - passing string and not list of strings results in strange behavior (query1.filter_provides("dnf")).

@j-mracek j-mracek moved this from Backlog to In Progress in DNF team Dec 13, 2023
@j-mracek
Copy link
Contributor Author

It looks like that when string is passed query1.filter_provides("dnf") it is automatically converted to std::vector{"d", "n", "f"}. The problem is that that this incorrect conversion is not visible and hard to debug, because it returns some results time to time.

@j-mracek
Copy link
Contributor Author

j-mracek commented Dec 14, 2023

I've created two draft PR that represents alternative solutions.

The first adds an additional overload method to hpp. This approach is potentially problematic, but nicer.

The second adds the method only for Python binding.

To fix the issue completely it would require modifying a lot of methods, therefore I would like to know preferable way before implementation.

May I ask you for your opinion?

@m-blaha
Copy link
Member

m-blaha commented Dec 14, 2023

I personally prefer the additional overload. This makes the API the same across all languages.

@kontura kontura changed the title Python byndings for query.filter_<>() behaves strangly Python byndings for query.filter_<>() behaves strangely Dec 14, 2023
@inknos
Copy link
Collaborator

inknos commented Dec 14, 2023

https://github.com/rpm-software-management/dnf5/pull/1101adds an additional overload method to hpp. This approach is potentially problematic, but nicer.

#1101 adds the method only for Python binding.

@j-mracek please, check the links, they both go to 1101, but I believe you wanted to go to 1102

I also prefer the solution with the overload.

@jan-kolarik jan-kolarik added this to the Fedora 40 milestone Jan 30, 2024
@jan-kolarik jan-kolarik changed the title Python byndings for query.filter_<>() behaves strangely Python bindings for query.filter_<>() behaves strangely Jan 30, 2024
@j-mracek
Copy link
Contributor Author

The issue is fixed by #1216

@github-project-automation github-project-automation bot moved this from In Progress to Done in DNF team Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take
Projects
Archived in project
Development

No branches or pull requests

5 participants