Skip to content

Commit

Permalink
Container.status returns unknown if TypeError
Browse files Browse the repository at this point in the history
Status should return unknown when TypeError occours. This exception can
be thrown after containers.list() is called and c.status is accessed
before c.reload()

client = PodmanClient()
clist = client.containers.list()
clist[0].status # TypeError without fix

Fixes: #446

Signed-off-by: Nicola Sella <[email protected]>
  • Loading branch information
inknos committed Oct 17, 2024
1 parent 5d986e6 commit fa92dd7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion podman/domain/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def labels(self):
def status(self):
"""Literal["running", "stopped", "exited", "unknown"]: Returns status of container."""
with suppress(KeyError):
return self.attrs["State"]["Status"]
try:
return self.attrs["State"]["Status"]
except TypeError as e:
logger.debug(f"Error getting container status: {e}")
return "unknown"

@property
Expand Down

0 comments on commit fa92dd7

Please sign in to comment.