diff --git a/compose/legacy.py b/compose/legacy.py index c9ec65817..6fbf74d69 100644 --- a/compose/legacy.py +++ b/compose/legacy.py @@ -149,7 +149,7 @@ def _get_legacy_containers_iter( for service in services: for container in containers: - if LABEL_VERSION in container['Labels']: + if LABEL_VERSION in (container.get('Labels') or {}): continue name = get_container_name(container) diff --git a/tests/integration/legacy_test.py b/tests/integration/legacy_test.py index 806b9a457..f79089b20 100644 --- a/tests/integration/legacy_test.py +++ b/tests/integration/legacy_test.py @@ -1,4 +1,5 @@ import unittest +from mock import Mock from docker.errors import APIError @@ -64,6 +65,22 @@ class UtilitiesTestCase(unittest.TestCase): legacy.is_valid_name("composetest_web_lol_1", one_off=True), ) + def test_get_legacy_containers_no_labels(self): + client = Mock() + client.containers.return_value = [ + { + "Id": "abc123", + "Image": "def456", + "Name": "composetest_web_1", + "Labels": None, + }, + ] + + containers = list(legacy.get_legacy_containers( + client, "composetest", ["web"])) + + self.assertEqual(len(containers), 1) + class LegacyTestCase(DockerClientTestCase):