containers / podman-py

Python bindings for Podman's RESTful API
Apache License 2.0
247 stars 88 forks source link

Running a locally non-existent image fails with AttributeError #378

Closed rsommer closed 1 month ago

rsommer commented 6 months ago

The code for running a new container with an image that is not present locally tries to access the ImagesManager via self.client.images as seen here: https://github.com/containers/podman-py/blob/53b238b75f7419f55560d6b5ef7d24729cd186bd/podman/domain/containers_run.py#L63 As self.client is an APIClient instance and not an instance of PodmanClient, an AttributeError occurs:

File /tmp/venv/lib/python3.11/site-packages/podman/domain/containers_run.py:63, in RunMixin.run(self, image, command, stdout, stderr, remove, **kwargs)
     61     container = self.create(image=image, command=command, **kwargs)
     62 except ImageNotFound:
---> 63     self.client.images.pull(image, platform=kwargs.get("platform"))
     64     container = self.create(image=image, command=command, **kwargs)
     66 container.start()

AttributeError: 'APIClient' object has no attribute 'images'

This is with podman-py==4.9.0 running against podman 4.9.2. podman versions prior to 4.8.0 contain another error preventing running a locally non-existing image (See: https://github.com/containers/podman-py/issues/231).

This can be reproduced with the following snippet (execute podman image rm docker.io/library/busybox:latest if you have already pulled busybox prior to testing):

#!/bin/bash
python3 -m venv venv
venv/bin/pip install podman==4.9.0
venv/bin/python -c 'import podman; client = podman.PodmanClient(base_url="unix:///run/podman/podman.sock"); client.containers.run("docker.io/library/busybox:latest")'