Skip to content

Commit 4699cfd

Browse files
aebmshin-
authored andcommitted
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 <[email protected]>
1 parent 8e724fc commit 4699cfd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

docker/models/images.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def tags(self):
3030
"""
3131
The image's tags.
3232
"""
33-
return [
34-
tag for tag in self.attrs.get('RepoTags', [])
35-
if tag != '<none>:<none>'
36-
]
33+
tags = self.attrs.get('RepoTags')
34+
if tags is None:
35+
tags = []
36+
return [tag for tag in tags if tag != '<none>:<none>']
3737

3838
def history(self):
3939
"""

tests/unit/models_images_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def test_tags(self):
8383
})
8484
assert image.tags == []
8585

86+
image = Image(attrs={
87+
'RepoTags': None
88+
})
89+
assert image.tags == []
90+
8691
def test_history(self):
8792
client = make_fake_client()
8893
image = client.images.get(FAKE_IMAGE_ID)

0 commit comments

Comments
 (0)