[PR #11645/a09e879f backport][stable-12] xfconf: fix boolean return values (#11650)

xfconf: fix boolean return values (#11645)

* xfconf: fix boolean return values

* add changelog frag

(cherry picked from commit a09e879ff2)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot]
2026-03-22 20:33:31 +01:00
committed by GitHub
parent 268b31b53d
commit 12808f67d5
3 changed files with 43 additions and 4 deletions

View File

@@ -0,0 +1,2 @@
bugfixes:
- xfconf - representation of boolean properties was not consistent between Python and ``xfconf-query``, leading to broken idempotency (https://github.com/ansible-collections/community.general/pull/11645).

View File

@@ -174,6 +174,8 @@ version:
version_added: 10.2.0 version_added: 10.2.0
""" """
from ansible.module_utils.parsing.convert_bool import boolean
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
from ansible_collections.community.general.plugins.module_utils.xfconf import get_xfconf_version, xfconf_runner from ansible_collections.community.general.plugins.module_utils.xfconf import get_xfconf_version, xfconf_runner
@@ -239,9 +241,6 @@ class XFConfProperty(StateModuleHelper):
self.vars.value = None self.vars.value = None
def state_present(self): def state_present(self):
# stringify all values - in the CLI they will all be happy strings anyway
# and by doing this here the rest of the code can be agnostic to it
self.vars.value = [str(v) for v in self.vars.value]
value_type = self.vars.value_type value_type = self.vars.value_type
values_len = len(self.vars.value) values_len = len(self.vars.value)
@@ -254,6 +253,14 @@ class XFConfProperty(StateModuleHelper):
# or complain if lists' lengths are different # or complain if lists' lengths are different
self.do_raise('Number of elements in "value" and "value_type" must be the same') self.do_raise('Number of elements in "value" and "value_type" must be the same')
# stringify all values - in the CLI they will all be happy strings anyway
# and by doing this here the rest of the code can be agnostic to it
# bool values are normalized to 'true'/'false' to match xfconf-query output format
self.vars.value = [
("true" if boolean(v) else "false") if vt == "bool" else str(v)
for v, vt in zip(self.vars.value, value_type)
]
# calculates if it is an array # calculates if it is an array
self.vars.is_array = bool(self.vars.force_array) or isinstance(self.vars.previous_value, list) or values_len > 1 self.vars.is_array = bool(self.vars.force_array) or isinstance(self.vars.previous_value, list) or values_len > 1

View File

@@ -78,6 +78,36 @@ test_cases:
rc: 0 rc: 0
out: '' out: ''
err: '' err: ''
- id: test_property_set_property_bool_same_value
input:
channel: xfce4-session
property: /general/SaveOnExit
state: present
value_type: bool
value: false
output:
changed: false
previous_value: 'false'
type: bool
value: 'false'
version: 4.18.1
mocks:
run_command:
- command: [/testbin/xfconf-query, --version]
environ: *env-def
rc: 0
out: *version-output
err: ''
- command: [/testbin/xfconf-query, --channel, xfce4-session, --property, /general/SaveOnExit]
environ: *env-def
rc: 0
out: "false\n"
err: ''
- command: [/testbin/xfconf-query, --channel, xfce4-session, --property, /general/SaveOnExit, --create, --type, bool, --set, 'false']
environ: *env-def
rc: 0
out: ''
err: ''
- id: test_property_set_property_bool_false - id: test_property_set_property_bool_false
input: input:
channel: xfce4-session channel: xfce4-session
@@ -89,7 +119,7 @@ test_cases:
changed: true changed: true
previous_value: 'true' previous_value: 'true'
type: bool type: bool
value: 'False' value: 'false'
version: 4.18.1 version: 4.18.1
mocks: mocks:
run_command: run_command: