Skip to content

xml.dom.minidom.Element.cloneNode fails with AttributeError #49101

Closed

Description

@exarkun
mannequin
BPO 4851
Nosy @loewis, @PCManticore, @berkerpeksag
Files
  • orphan_node_clone.patch: Patch fix
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-03-15.10:38:34.148>
    created_at = <Date 2009-01-05.22:00:10.082>
    labels = ['invalid', 'type-bug', 'library']
    title = 'xml.dom.minidom.Element.cloneNode fails with AttributeError'
    updated_at = <Date 2017-03-15.10:38:34.146>
    user = 'https://bugs.python.org/exarkun'

    bugs.python.org fields:

    activity = <Date 2017-03-15.10:38:34.146>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-03-15.10:38:34.148>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2009-01-05.22:00:10.082>
    creator = 'exarkun'
    dependencies = []
    files = ['25651']
    hgrepos = []
    issue_num = 4851
    keywords = ['patch', 'needs review']
    message_count = 5.0
    messages = ['79203', '109606', '161225', '289058', '289663']
    nosy_count = 6.0
    nosy_names = ['loewis', 'exarkun', 'Claudiu.Popa', 'Alexandre.Zani', 'berker.peksag', 'Craig Rodrigues']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4851'
    versions = ['Python 3.5']

    Activity

    1. exarkun commented on Jan 5, 2009

      exarkunmannequin
      MannequinAuthor

      It seems impossible to clone an Element created without a document:

        >>> Element('foo').cloneNode(False)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          File "/usr/lib/python2.5/xml/dom/minidom.py", line 211, in cloneNode
            return _clone_node(self, deep, self.ownerDocument or self)
          File "/usr/lib/python2.5/xml/dom/minidom.py", line 1814, in _clone_node
            if node.ownerDocument.isSameNode(newOwnerDocument):
        AttributeError: 'NoneType' object has no attribute 'isSameNode'

      The documentation claims that cloneNode was fixed for releases
      "subsequent" to 2.0, but this doesn't appear to be true.

      http://docs.python.org/library/xml.dom.minidom.html#xml.dom.minidom.Node.cloneNode

      A similar issue occurs when attempting to import a node into a document
      (something I tried as a work-around for this failure):

        >>> d.importNode(e, False)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          File "/usr/lib/python2.5/xml/dom/minidom.py", line 1737, in importNode
            return _clone_node(node, deep, self)
          File "/usr/lib/python2.5/xml/dom/minidom.py", line 1814, in _clone_node
            if node.ownerDocument.isSameNode(newOwnerDocument):
        AttributeError: 'NoneType' object has no attribute 'isSameNode'
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jan 5, 2009
    3. BreamoreBoy commented on Jul 8, 2010

      BreamoreBoymannequin
      Mannequin

      Has this simply slipped under the radar?

    4. AlexandreZani commented on May 20, 2012

      AlexandreZanimannequin
      Mannequin

      This patch allows the cloning of elements that do not have a document owner.

      If a node does not have a document owner, a new document owner is created for the clone.

    5. CraigRodrigues commented on Mar 6, 2017

      CraigRodriguesmannequin
      Mannequin

      This looks like a duplicate of https://bugs.python.org/issue15290

      15290 was closed as invalid, and the submitter was told that the
      code should be changed to not rely on creating elements outside
      of the document interface.

      I encountered the same problem when trying to port Twisted to Python 3.

    6. berkerpeksag commented on Mar 15, 2017

      @berkerpeksag
      Member

      Thanks for your detective work, Craig. MvL is correct that those classes should be created via a Document object. I'm marking bpo-15290 as a duplicate of this.

      Note that we can reopen this if you'd like to propose a documentation patch or PR to make the current docs clearer. Thanks!

    7. transferred this issue fromon Apr 10, 2022
    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/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions