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

setAttribute() can fail #59495

Closed
pitrou opened this issue Jul 7, 2012 · 7 comments
Closed

setAttribute() can fail #59495

pitrou opened this issue Jul 7, 2012 · 7 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Jul 7, 2012

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

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 7, 2012

    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

    @pitrou pitrou added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 7, 2012
    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 8, 2012

    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

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 8, 2012

    Here is a patch.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jul 8, 2012

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

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 8, 2012

    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.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jul 8, 2012

    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.

    @loewis loewis mannequin added the invalid label Jul 8, 2012
    @loewis loewis mannequin closed this as completed Jul 8, 2012
    @CraigRodrigues
    Copy link
    Mannequin

    CraigRodrigues mannequin commented Mar 6, 2017

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

    @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

    2 participants