From 4c220c4d7405a9f89dde0ecc5e7db6fab7209626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20J=C3=A4hnel?= Date: Sun, 12 Nov 2023 11:19:56 +0100 Subject: [PATCH] fix(community.docker.docker_volume): labels can be none (#702) * fix(community.docker.docker_volume): labels can be none catch case where volume labels can are done (default) eg: $ docker volume inspect foo [ { "CreatedAt": "2023-11-11T12:55:23+01:00", "Driver": "local", "Labels": null, "Mountpoint": "/var/lib/docker/volumes/foo/_data", "Name": "foo", "Options": {}, "Scope": "local" } ] * Update plugins/modules/docker_volume.py Co-authored-by: Felix Fontein * add(community.docker.docker_volume): changelog fragment * Update changelogs/fragments/702-docker-volume-label-none.yaml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- changelogs/fragments/702-docker-volume-label-none.yaml | 2 ++ plugins/modules/docker_volume.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/702-docker-volume-label-none.yaml diff --git a/changelogs/fragments/702-docker-volume-label-none.yaml b/changelogs/fragments/702-docker-volume-label-none.yaml new file mode 100644 index 000000000..d1c9c8471 --- /dev/null +++ b/changelogs/fragments/702-docker-volume-label-none.yaml @@ -0,0 +1,2 @@ +bugfixes: + - docker_volume - fix crash caused by accessing an empty dictionary. The ``has_different_config()`` was raising an ``AttributeError`` because the ``self.existing_volume["Labels"]`` dictionary was ``None`` (https://github.com/ansible-collections/community.docker/pull/702). diff --git a/plugins/modules/docker_volume.py b/plugins/modules/docker_volume.py index 9a2ba1ff2..f282cafd0 100644 --- a/plugins/modules/docker_volume.py +++ b/plugins/modules/docker_volume.py @@ -214,7 +214,7 @@ def has_different_config(self): parameter=value, active=self.existing_volume['Options'].get(key)) if self.parameters.labels: - existing_labels = self.existing_volume.get('Labels', {}) + existing_labels = self.existing_volume.get('Labels') or {} for label in self.parameters.labels: if existing_labels.get(label) != self.parameters.labels.get(label): differences.add('labels.%s' % label,