From be9afb48003fc130f7b6ac9c5914fbf0e06e6e95 Mon Sep 17 00:00:00 2001 From: RoboticInterface <87591750+RoboticInterface@users.noreply.github.com> Date: Thu, 28 May 2026 14:52:24 -0500 Subject: [PATCH] xml: false positive python2 string type check bugfix (#12108) * bugfixes: - xml: fix false positive type check failure for string values on Python 2 hosts, where ``json_dict_bytes_to_unicode`` guarantees unicode output but ``isinstance(value, str)`` only matches byte strings. * changelog fragment for xml false positive type check failure. * Rename xml-python2-string-isinstance to 12108-fix-xml-python2-string-isinstance * Rename 12108-fix-xml-python2-string-isinstance to 12108-fix-xml-python2-string-isinstance.yml * Update changelogs/fragments/12108-fix-xml-python2-string-isinstance.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- .../fragments/12108-fix-xml-python2-string-isinstance.yml | 5 +++++ plugins/modules/xml.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/12108-fix-xml-python2-string-isinstance.yml diff --git a/changelogs/fragments/12108-fix-xml-python2-string-isinstance.yml b/changelogs/fragments/12108-fix-xml-python2-string-isinstance.yml new file mode 100644 index 0000000000..c90fc798e7 --- /dev/null +++ b/changelogs/fragments/12108-fix-xml-python2-string-isinstance.yml @@ -0,0 +1,5 @@ +bugfixes: + - xml - fix false positive type check failure for string values on Python 2 + hosts, where ``json_dict_bytes_to_unicode`` guarantees unicode output but + ``isinstance(value, str)`` only matches byte strings + (https://github.com/ansible-collections/community.general/issues/12107, https://github.com/ansible-collections/community.general/pull/12108). diff --git a/plugins/modules/xml.py b/plugins/modules/xml.py index 25e6609ec0..ae93122a21 100644 --- a/plugins/modules/xml.py +++ b/plugins/modules/xml.py @@ -689,7 +689,7 @@ def set_target_inner(module, tree, xpath, namespaces, attribute, value): module.fail_json(msg="Xpath %s does not reference a node! tree is %s" % (xpath, etree.tostring(tree, pretty_print=True))) - if not isinstance(value, str): + if not isinstance(value, string_types): target = ("attribute '{attribute}' at xpath '{xpath}'" if attribute else "element text at xpath '{xpath}'").format(attribute=attribute, xpath=xpath) module.fail_json( msg=(