containers / containers/podman-py
PodmanClient(connection=...) unusable without an identity; explicit identity= is ignored
- Dominant language
- Python
- Stars
- 381
- Forks
- 140
- Avg merge
- 5h 30m
- Merged PRs (30d)
- 1
Description
### Summary
`PodmanClient(connection=...)` cannot be used with a connection that has no identity, and passing an explicit `identity=` does **not** work around it, because the fallback is evaluated eagerly.
### Code (current `main`, `client.py`)
```python
api_kwargs["identity"] = kwargs.get("identity", str(connection.identity))
```
`str(connection.identity)` is a default *argument*, so Python evaluates it before `kwargs.get` runs — even when the caller supplied `identity`. With no identity configured, `connection.identity` is `Path(None)` and raises (see the separate report on `ServiceConnection.identity`).
The same pattern is used on the `active_service` path, so a bare `PodmanClient()` fails on a system whose active connection has no identity.
### Reproducer
```python
from podman import PodmanClient
PodmanClient(connection="remote-with-key") # OK
PodmanClient(connection="local") # TypeError
PodmanClient(connection="local", identity="/dev/null") # TypeError <-- explicit identity ignored
```
Measured against a host with a `unix://` connection named `local`.
### Expected
The explicit `identity=` is honoured, and a connection without one simply omits the argument.
### Suggested fix
Compute the fallback lazily:
```python
identity = kwargs.get("identity") or connection.attrs.get("Identity") or connection.attrs.get("identity")
if identity:
api_kwargs["identity"] = identity
```
### Environment
podman-py 5.6.0 (Fedora `python3-podman-5.6.0-4.fc44`), podman 5.8.4 client and server, rootless, Python 3.14. Re-checked against current `main` before filing.
Contributor guide
Research direction
Start in client.py and inspect how PodmanClient handles the connection and active_service paths when building api_kwargs. Reproduce the three calls from the issue, then verify that explicit identity is honored and that connections without an identity omit the argument without raising.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100