Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
exarkun mannequin opened this issue Jan 5, 2009 · 5 comments
Closed

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

exarkun mannequin opened this issue Jan 5, 2009 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@exarkun
Copy link
Mannequin

exarkun mannequin commented Jan 5, 2009

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']

    @exarkun
    Copy link
    Mannequin Author

    exarkun mannequin commented Jan 5, 2009

    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'

    @exarkun exarkun mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 5, 2009
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 8, 2010

    Has this simply slipped under the radar?

    @AlexandreZani
    Copy link
    Mannequin

    AlexandreZani mannequin commented May 20, 2012

    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.

    @CraigRodrigues
    Copy link
    Mannequin

    CraigRodrigues mannequin commented Mar 6, 2017

    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.

    @berkerpeksag
    Copy link
    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!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant