Fix Element truth-value deprecation warnings in salt.utils.xmlutil - #69904
Open
bogdanr wants to merge 1 commit into
Open
Fix Element truth-value deprecation warnings in salt.utils.xmlutil#69904bogdanr wants to merge 1 commit into
bogdanr wants to merge 1 commit into
Conversation
`_to_dict`, `_to_full_dict`, and `clean_node` tested the truth value of
`xml.etree.ElementTree.Element` objects directly (e.g. `if not
xmltree:`, `if item:`, `if ... and parent:`). An Element's truth value
is defined by whether it has children, which Python deprecates in favor
of explicit `len(elem)`/`elem is not None` checks:
DeprecationWarning: Testing an element's truth value will always
return True in future versions. Use specific 'len(elem)' or 'elem
is not None' test instead.
`salt.utils.aws.query()` calls `xmlutil.to_dict()` on essentially every
AWS API response, so this warning fires on every single AWS API call
made through the `ec2` cloud driver (and anywhere else parsing XML via
this module, e.g. the virt module's `change_xml`).
This is the same underlying issue as saltstack#56475 (getchildren() deprecation
in the same file), which addressed iteration but missed truth-value
testing.
Fixes saltstack#69903
twangboy
requested changes
Jul 29, 2026
twangboy
left a comment
Contributor
There was a problem hiding this comment.
Please rebase this on the earliest branch where this but exists, probably 3006.x.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #69903.
salt.utils.xmlutil._to_dict,_to_full_dict, andclean_nodetested the truth value ofxml.etree.ElementTree.Elementobjects directly (e.g.if not xmltree:,if item:,if ... and parent:). AnElement's truth value is defined by whether it has children, which Python deprecates in favor of explicitlen(elem)/elem is not Nonechecks, emitting:salt.utils.aws.query()callsxmlutil.to_dict()on essentially every AWS API response, so this fires on every single AWS API call made through theec2cloud driver (recently extracted to saltext-cloud), and anywhere else parsing XML via this module (e.g. the virt module'schange_xml).This is the same class of issue as #56475 (
getchildren()deprecation in the same file), which addressed iteration but missed truth-value testing.What issues does this PR fix or reference?
Fixes #69903
Related to #56475
Previous Behavior
salt.utils.xmlutil.to_dict()/change_xml()emitDeprecationWarning: Testing an element's truth value...on every call.New Behavior
No warning is emitted; behavior of
to_dict()/change_xml()is unchanged (verified against all existingto_dicttest cases in both old- and new-style test suites, plus a new regression test asserting no such warning is raised).