Skip to content

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

@PersonBelowRocks

Description

@PersonBelowRocks

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions