containers / containers/podman-py
`ContainersManager.list()` with label list filter doesn't perform filtering correctly
- Dominant language
- Python
- Stars
- 381
- Forks
- 140
- Avg merge
- 5h 30m
- Merged PRs (30d)
- 1
Description
(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](https://podman-py.readthedocs.io/en/latest/podman.domain.containers_manager.html#podman.domain.containers_manager.ContainersManager.list), `ContainersManager.list()` should support a `filters` keyword argument where you can filter on multiple labels, like so:
```python
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](https://github.com/containers/podman-py/blob/2a29132efab4a183580a30d9c18b9bdb61b5ab49/podman/api/http_utils.py#L46))
```python
# 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.
Contributor guide
Research direction
Start in api/http_utils.py at _format_dict and trace how ContainersManager.list() builds the request criteria from filters. Reproduce the documented multiple-label example against the Podman socket, then verify that separate labels are sent and matching containers are returned while single-label filtering still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100