Skip to content

Calling ElementTree.write on an ElementTree instance where ElementTree._root is the wrong type causes possible data loss #135640

Closed

Description

@abstractedfox

Bug report

Bug description:

Example:

tree = xml.etree.ElementTree.ElementTree(element = "") # element should be an ElementTree.Element object or None
tree.write("file.xml") # This appropriately causes a traceback, but blanks file.xml if it exists

PR coming with a fix!

CPython versions tested on:

CPython main branch, 3.14

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    and removed on Jun 19, 2025
  2. added a commit that references this issue on Jul 3, 2025
  3. added 2 commits that reference this issue on Jul 3, 2025
  4. added 2 commits that reference this issue on Jul 3, 2025
  5. serhiy-storchaka commented on Jul 3, 2025

    @serhiy-storchaka
    Member

    Thank you for your contribution @abstractedfox.

    There is also other problem here. See #136231.

  6. added a commit that references this issue on Jul 11, 2025
  7. added a commit that references this issue on Jul 12, 2025
  8. added a commit that references this issue on Jul 13, 2025
  9. added a commit that references this issue on Aug 4, 2025
  10. added a commit that references this issue on Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions