Skip to content

setAttribute() can fail #59495

Closed
Closed

Description

@pitrou
BPO 15290
Nosy @loewis, @pitrou
Superseder
  • bpo-4851: xml.dom.minidom.Element.cloneNode fails with AttributeError
  • Files
  • minidom_setattribute.patch
  • 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 2012-07-08.12:58:32.395>
    created_at = <Date 2012-07-07.23:32:43.695>
    labels = ['type-bug', 'library']
    title = 'setAttribute() can fail'
    updated_at = <Date 2017-03-15.10:38:12.386>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2017-03-15.10:38:12.386>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-07-08.12:58:32.395>
    closer = 'loewis'
    components = ['Library (Lib)']
    creation = <Date 2012-07-07.23:32:43.695>
    creator = 'pitrou'
    dependencies = []
    files = ['26317']
    hgrepos = []
    issue_num = 15290
    keywords = ['patch']
    message_count = 7.0
    messages = ['164954', '165007', '165008', '165009', '165010', '165011', '289063']
    nosy_count = 3.0
    nosy_names = ['loewis', 'pitrou', 'Craig Rodrigues']
    pr_nums = []
    priority = 'high'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '4851'
    type = 'behavior'
    url = 'https://bugs.python.org/issue15290'
    versions = ['Python 3.3']

    Activity

    1. pitrou commented on Jul 7, 2012

      @pitrou
      MemberAuthor

      This is a regression from 3.2:

      Traceback (most recent call last):
        File "/home/antoine/3sted/twisted/lore/test/test_lore.py", line 542, in test_setTitle
          secondTitle.setAttribute('class', 'title')
        File "/home/antoine/opt/lib/python3.3/xml/dom/minidom.py", line 743, in setAttribute
          attr.ownerDocument = self.ownerDocument
      builtins.AttributeError: ownerDocument
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jul 7, 2012
    3. pitrou commented on Jul 8, 2012

      @pitrou
      MemberAuthor

      Trivial reproducer:

      >>> e = minidom.Element("span")
      >>> e.setAttribute("class", "version")
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/home/antoine/cpython/default/Lib/xml/dom/minidom.py", line 743, in setAttribute
          attr.ownerDocument = self.ownerDocument
      AttributeError: ownerDocument
    4. pitrou commented on Jul 8, 2012

      @pitrou
      MemberAuthor

      Here is a patch.

    5. loewis commented on Jul 8, 2012

      loewismannequin
      Mannequin

      That's invalid usage. You are supposed to create new element nodes through the document's createElement method. "unattached" nodes are not supported.

    6. pitrou commented on Jul 8, 2012

      @pitrou
      MemberAuthor

      That's invalid usage. You are supposed to create new element nodes
      through the document's createElement method. "unattached" nodes are
      not supported.

      Well, I don't know how many third-party application rely on this, but
      Twisted does it.

    7. loewis commented on Jul 8, 2012

      loewismannequin
      Mannequin

      Then Twisted will have to change. From

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

      "Applications should not instantiate the classes themselves; they should use the creator functions available on the Document object."

      If they insist on not using createElement, they use internal API, and need to adjust that to new Python versions.

      Closing as invalid.

    8. CraigRodrigues commented on Mar 6, 2017

      CraigRodriguesmannequin
      Mannequin

      Same issue was brought up in http://bugs.python.org/issue4851

    9. 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