containers / containers/podman-py
PodmanClient(connection=...) unusable without an identity; explicit identity= is ignored
- Lenguaje dominante
- Python
- Estrellas
- 381
- Forks
- 140
- Merge medio
- 5 h 30 min
- PR fusionados (30 d)
- 1
Descripción
### 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.
Guía de contribución
Línea de trabajo
Comienza en client.py e inspecciona cómo PodmanClient gestiona las rutas connection y active_service al construir api_kwargs. Reproduce las tres llamadas del issue y verifica después que se respete una identity explícita y que las conexiones sin identity omitan el argumento sin generar una excepción.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Activo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 78/100