Skip to content

fix_step_badges.py crashes: defusedxml.ElementTree has no indent attribute on older defusedxml #167

@agorokh

Description

@agorokh

Summary

plugins/deploy-on-aws/scripts/lib/fix_step_badges.py calls defusedxml.ElementTree.indent(...) but defusedxml.ElementTree does not export an indent() function on older releases. The stdlib xml.etree.ElementTree.indent() was added in Python 3.9, and defusedxml did not mirror it until a relatively recent release. On systems with an older defusedxml (still commonly installed via system Python, distro packages, or pinned envs), the badge post-processor crashes with:

AttributeError: module 'defusedxml.ElementTree' has no attribute 'indent'

The offending line is fix_step_badges.py:486:

import defusedxml.ElementTree as ET
...
ET.indent(tree, space="  ")

Steps to reproduce

  1. Install the deploy-on-aws plugin from awslabs/agent-plugins.
  2. In an environment with an older defusedxml (one that doesn't re-export indent), generate any architecture diagram that triggers the post-processing pipeline.
  3. The badge-overlap fixer step crashes with the AttributeError above.

Workaround

Monkey-patch defusedxml.ElementTree.indent = xml.etree.ElementTree.indent before invoking the script.

Suggested fix

indent() is a pure write-side, pretty-print operation — there is no XML-parsing security risk in falling back to the stdlib implementation. Keep defusedxml for parsing, use stdlib indent for output:

import xml.etree.ElementTree as _ET
import defusedxml.ElementTree as ET
...
# defusedxml lacks indent() on older versions; stdlib indent is safe here
# because it's a write-only pretty-print, not parsing.
try:
    ET.indent(tree, space="  ")
except AttributeError:
    _ET.indent(tree, space="  ")

Alternatively, just bump the minimum defusedxml version in the plugin's requirements to one that ships indent().

Happy to send a small PR with the one-line patch if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions