This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: setAttribute() can fail
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: xml.dom.minidom.Element.cloneNode fails with AttributeError
View: 4851
Assigned To: Nosy List: Craig Rodrigues, loewis, pitrou
Priority: high Keywords: patch

Created on 2012-07-07 23:32 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
minidom_setattribute.patch pitrou, 2012-07-08 12:09 review
Messages (7)
msg164954 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-07 23:32
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
msg165007 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-08 11:57
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
msg165008 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-08 12:09
Here is a patch.
msg165009 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-07-08 12:29
That's invalid usage. You are supposed to create new element nodes through the document's createElement method. "unattached" nodes are not supported.
msg165010 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-08 12:31
> 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.
msg165011 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-07-08 12:58
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.
msg289063 - (view) Author: Craig Rodrigues (Craig Rodrigues) Date: 2017-03-06 03:15
Same issue was brought up in http://bugs.python.org/issue4851
History
Date User Action Args
2022-04-11 14:57:32adminsetgithub: 59495
2017-03-15 10:38:12berker.peksagsetsuperseder: xml.dom.minidom.Element.cloneNode fails with AttributeError
resolution: not a bug -> duplicate
stage: patch review -> resolved
2017-03-06 03:15:36Craig Rodriguessetnosy: + Craig Rodrigues
messages: + msg289063
2012-07-08 12:58:32loewissetstatus: open -> closed
resolution: not a bug
messages: + msg165011
2012-07-08 12:31:00pitrousetmessages: + msg165010
2012-07-08 12:29:11loewissetmessages: + msg165009
2012-07-08 12:09:01pitrousetfiles: + minidom_setattribute.patch
keywords: + patch
messages: + msg165008

stage: patch review
2012-07-08 11:57:43pitrousetmessages: + msg165007
2012-07-07 23:32:43pitroucreate