Fix label sanitization error handling. (#1029)

This commit is contained in:
Felix Fontein 2025-01-22 21:45:08 +01:00 committed by GitHub
parent 9e26c4794e
commit 9cc70f5202
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- "Fix label sanitization code to avoid crashes in case of errors (https://github.com/ansible-collections/community.docker/issues/1028, https://github.com/ansible-collections/community.docker/pull/1029)."

View File

@ -282,7 +282,7 @@ class DifferenceTracker(object):
def sanitize_labels(labels, labels_field, client=None, module=None):
def fail(msg):
if client is not None:
client.module.fail(msg)
client.fail(msg)
if module is not None:
module.fail_json(msg=msg)
raise ValueError(msg)

View File

@ -118,6 +118,14 @@
## labels ##########################################################
####################################################################
- name: Create a volume with an invalid label
docker_volume:
name: "{{ vname }}"
labels:
foo: 1.0
register: driver_labels_invalid
ignore_errors: true
- name: Create a volume with labels
docker_volume:
name: "{{ vname }}"
@ -173,6 +181,8 @@
- assert:
that:
- driver_labels_invalid is failed
- driver_labels_invalid.msg == "The value 1.0 for 'foo' of labels is not a string or something than can be safely converted to a string!"
- driver_labels_1 is changed
- driver_labels_2 is not changed
- driver_labels_3 is not changed