Skip to content

Exception retrieving untagged images on api >= 1.24 #1351

@hobosteaux

Description

@hobosteaux

Docker API >= 1.24 will return a null object if image tags DNE instead of not including it in the response. This makes the dict.get fail to catch the null case and the list comprehension to iterate over a non-iterable.

  File "<stdin>", line 1, in <module>
  File "docker/models/images.py", line 16, in __repr__
    return "<%s: '%s'>" % (self.__class__.__name__, "', '".join(self.tags))
  File "docker/models/images.py", line 34, in tags
    tag for tag in self.attrs.get('RepoTags', [])
TypeError: 'NoneType' object is not iterable

This is similar to an issue seen in salt

Was able to get things working with a pretty quick change:

diff --git a/docker/models/images.py b/docker/models/images.py
index 32068e6..39a640d 100644
--- a/docker/models/images.py
+++ b/docker/models/images.py
@@ -30,9 +30,11 @@ class Image(Model):
         """
         The image's tags.
         """
+        tags = self.attrs.get('RepoTags', [])
+        if tags is None:
+            return []
         return [
-            tag for tag in self.attrs.get('RepoTags', [])
-            if tag != '<none>:<none>'
+            tag for tag in tags if tag != '<none>:<none>'
         ]
 
     def history(self):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions