From 95b6fddd14b9b3556d6a929bbf66affc1a5daa61 Mon Sep 17 00:00:00 2001 From: "Alejandro E. Brito Monedero" Date: Mon, 16 Jan 2017 08:48:41 +0100 Subject: [PATCH] Fix #1351 * Fix TypeError when getting the tags property from an image that has no tags. Ex: An image pulled by cryptohash. It is handled like when the image doesn't have defined the RepoTags member. Signed-off-by: Alejandro E. Brito Monedero --- docker/models/images.py | 8 ++++---- tests/unit/models_images_test.py | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docker/models/images.py b/docker/models/images.py index 32068e69..6f8f4fe2 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -30,10 +30,10 @@ class Image(Model): """ The image's tags. """ - return [ - tag for tag in self.attrs.get('RepoTags', []) - if tag != ':' - ] + tags = self.attrs.get('RepoTags') + if tags is None: + tags = [] + return [tag for tag in tags if tag != ':'] def history(self): """ diff --git a/tests/unit/models_images_test.py b/tests/unit/models_images_test.py index 392c58d7..efb21166 100644 --- a/tests/unit/models_images_test.py +++ b/tests/unit/models_images_test.py @@ -83,6 +83,11 @@ class ImageTest(unittest.TestCase): }) assert image.tags == [] + image = Image(attrs={ + 'RepoTags': None + }) + assert image.tags == [] + def test_history(self): client = make_fake_client() image = client.images.get(FAKE_IMAGE_ID)