Skip to content

Commit

Permalink
fix(community.docker.docker_volume): labels can be none (#702)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* add(community.docker.docker_volume): changelog fragment

* Update changelogs/fragments/702-docker-volume-label-none.yaml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 4c220c4)
  • Loading branch information
chaoslion authored and patchback[bot] committed Nov 12, 2023
1 parent 5f413ac commit f16bd66
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/702-docker-volume-label-none.yaml
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion plugins/modules/docker_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,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,
Expand Down

0 comments on commit f16bd66

Please sign in to comment.