glideinWMS / glideinwms

The glideinWMS Project
http://tinyurl.com/glideinwms
Apache License 2.0
16 stars 46 forks source link

Deprecation of getchildren() in ElementTree #302

Closed namrathaurs closed 1 year ago

namrathaurs commented 1 year ago

Fixes #299.

A quick search of the AttributeError revealed that getchildren() method has been deprecated since Python 3.2 but has not been warned about until v3.8. Further, the deprecation has been removed in Python 3.9. [This was also suspected by Bruno Coimbra during a discussion]

Ref: Python 3.8 documentation

As part of the investigation, also checked to compare the deprecated behavior of getchildren() [from Python 3.6] with list() from v3.8+ to make sure the outputs were identical (i.e. the result set and the type of the result). The outputs, along with their type, from the deprecated and the current approaches seems to be consistent with one another. (Thanks to @BrunoCoimbra for recommending to do this exercise as part of the investigation!)

Following is the code snippet from the testing: ()

[root@fermicloud512 gwms-frontend]# python3
Python 3.6.8 (default, Nov 10 2020, 07:30:01) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.etree.ElementTree as ET
>>> a = ET.Element('a')
>>> b = ET.SubElement(a, 'b')
>>> c = ET.SubElement(a, 'c')
>>> d = ET.SubElement(a, 'd')
>>> e = ET.SubElement(b, 'e')
>>> f = ET.SubElement(d, 'f')
>>> g = ET.SubElement(d, 'g')
>>> for child in a.getchildren():
...     print(child)
... 
<Element 'b' at 0x7f29cf306f98>
<Element 'c' at 0x7f29cf28b958>
<Element 'd' at 0x7f29cf28b2c8>
>>> for child in a.getchildren():
...     print(type(child))
... 
<class 'xml.etree.ElementTree.Element'>
<class 'xml.etree.ElementTree.Element'>
<class 'xml.etree.ElementTree.Element'>
>>> for child in list(a):
...     print(child)
... 
<Element 'b' at 0x7f29cf306f98>
<Element 'c' at 0x7f29cf28b958>
<Element 'd' at 0x7f29cf28b2c8>
>>> for child in list(a):
...     print(type(child))
... 
<class 'xml.etree.ElementTree.Element'>
<class 'xml.etree.ElementTree.Element'>
<class 'xml.etree.ElementTree.Element'>
>>> 
namrathaurs commented 1 year ago

To fix the AttributeError, that is caused due to the deprecation of getchildren() method in the xml.etree.ElementTree module, on a system with Python 3.9, you need to patch the Frontend and Factory running GlideinWMS v3.10.2 with the file from this PR.

Frontend: replace /usr/lib/python3.6/site-packages/glideinwms/creation/lib/check_python3_expr.py with the file here. Factory: replace /usr/lib/python3.6/site-packages/glideinwms/creation/lib/check_python3_expr.py with the file here.

After replacing the files, restart Factory and Frontend.