containers / containers/podman-py
PodmanClient(connection=...) unusable without an identity; explicit identity= is ignored
- Lingua principale
- Python
- Stelle
- 381
- Fork
- 140
- Merge medio
- 5h 30m
- PR unite (30g)
- 1
Descrizione
### 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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Attiva
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 78/100