Skip to content

minidom renameNode() drops an attribute renamed to a prefixed name #159637

Open

Description

@fedonman

Bug description:

Since gh-156665, Document.renameNode() raises NamespaceErr when it renames an attribute with no namespace to a prefixed name in a namespace, and the attribute has already been removed from its element when the error is raised.

from xml.dom.minidom import parseString
doc = parseString('<r a="1" b="2"/>')
attr = doc.documentElement.getAttributeNode('a')
try:
    doc.renameNode(attr, 'http://example.com/ns', 'p:a')
except Exception as e:
    print(type(e).__name__, e)
print(doc.documentElement.toxml())
NamespaceErr cannot use the prefix 'p' with an empty namespace
<r b="2"/>

Expected: the attribute is renamed to p:a in http://example.com/ns and stays on the element, as on 3.15.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 17, 2026
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