podman-py icon indicating copy to clipboard operation
podman-py copied to clipboard

`ContainersManager.list()` with label list filter doesn't perform filtering correctly

Open PersonBelowRocks opened this issue 8 months ago • 1 comments

(not very familiar with podman or even python, feel free to close this if this is just a big misunderstanding)

Using package version 5.4.0.1

Expected Behavior

According to the documentation, ContainersManager.list() should support a filters keyword argument where you can filter on multiple labels, like so:

filters = {
    "label": [
        "my.example.label=value1",
        "my.other.example.label=value2"
    ]
}

containers_manager.list(filters=filters)

Running this I'd expect to get a list of all containers that have the specified tags.

Observed Behaviour

Listing containers with such a filter on my local environment returned no containers. But when I manually sent an HTTP request to the socket I got the expected result with the expected containers.

I can provide a more thorough example or logs if needed, just let me know.

Theory?

After some debugging it seems like the function _format_dict in api/http_utils.py is a bit too eager to convert everything into a string. (permalink)

# in api/http_utils.py

def _format_dict(filters, criteria):
    for key, value in filters.items():
        if value is None:
            continue
        str_value = str(value) # list turns into a string here

        if key in criteria:
            criteria[key].append(str_value)
        else:
            criteria[key] = [str_value]

This then leads to a request with a label filter with only one label, and that label is the string representation of the list of labels I provided to the filter. This is obviously only a problem with a label list, which makes filtering on a single label work fine.

PersonBelowRocks avatar Apr 21 '25 12:04 PersonBelowRocks

hey, @PersonBelowRocks, I am shifting from one priority to another, so this got out of my radar. sorry for the huge delay.

Now, this is definitely a bug, and I definitely have interest in this fix. But, if you want to do it yourself, I can help you with code review, tests, and our automation. would you like to work on it?

inknos avatar Sep 23 '25 14:09 inknos