saltstack / saltstack/salt

salt.utils.xmlutil relies on deprecated Element truth-value testing

Open Beginner friendly
#69,903 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description of Issue

salt/utils/xmlutil.py tests the truth value of xml.etree.ElementTree.Element objects directly (e.g. if not xmltree:, if item:, if ... and parent:), which triggers:

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.

This is emitted on every call to salt.utils.xmlutil.to_dict()/clean_node(), which is used by salt.utils.aws.query() for essentially every AWS API request/response (and therefore by every call made through the ec2 cloud driver, virt XML handling, etc).

This is the same underlying issue as #56475 (getchildren() deprecation in the same file), which was fixed for iteration but not for truth-value testing.

Steps to Reproduce Issue
import warnings
import xml.etree.ElementTree as ET
import salt.utils.xmlutil as xml

with warnings.catch_warnings():
    warnings.simplefilter("error")
    xml.to_dict(ET.fromstring("<parent>data</parent>"))
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.

Or simply run salt-cloud -p <profile> <name> against an ec2 provider and watch the logs.

Versions Report

Reproduced against current master with Python 3.14.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in salt/utils/xmlutil.py and inspect the truth-value checks in to_dict() and clean_node(), including the patterns shown in the issue. Run the provided warnings-as-errors reproduction with Python 3.14; done means the conversion completes without a DeprecationWarning while preserving the XML-to-dictionary behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.