After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 508352 - findChildren in tree.py needs a 'if children' check
findChildren in tree.py needs a 'if children' check
Status: RESOLVED FIXED
Product: dogtail
Classification: Deprecated
Component: Framework
0.6.1
Other All
: Normal normal
: ---
Assigned To: Dogtail Maintainers
Dogtail Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-01-09 18:38 UTC by Anand
Modified: 2008-01-09 18:54 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Anand 2008-01-09 18:38:49 UTC
Please describe the problem:
In findChildren, when children is None then we get TypeError. 
This is manifested in case of HyperLinks (directly?) under the node.

I am using python-dogtail 0.6.1-3ubuntu2 on ubuntu gutsy.


Steps to reproduce:
1.Open firefox and then any page with hyperlinks.
2.  Run the following in script or python prompt :

from dogtail import *

print tree.root.findChild(predicate.GenericPredicate(roleName='menu',name='Applications')).findChildren(predicate.GenericPredicate(roleName='menu item'))

print tree.root.findChildren(predicate.GenericPredicate(roleName='menu'))



Actual results:
The first call works.
The second one gives "TypeError: 'NoneType' object is not iterable"

Expected results:
The check given below solves the issue, 

>>        if children :
            for child in children:
                if child.satisfies(pred): selfList.append(child)
                if recursive:
             ...

I am not sure if it's the best approach or whether we should cover it in getattr in Node class. As this problem seems to have slipped through somehow it would be better to put in a check anycase.

(Also, see  "# Somehow, if we allow the children to be seen, things get weird." comment in class Link)

Does this happen every time?
Yes

Other information:
A similar check might be required in dump.py.

However even in this case when I do a tree.root.dump() even with the 'if node.children' check introduced in function 'plain', I get the following :

  • File "pyspi.pyx", line 1006 in atspi.Hyperlink.getObject
  • File "pyspi.pyx", line 245 in atspi.Base.__checkSelf

wrt above, I saw that only the Base class has as assertion, the others here raise an AttributeError. Should it be changed ?
Comment 1 Zack Cerza 2008-01-09 18:54:50 UTC
Thus bug is fixed in svn. The new behavior (not sure why this wasn't always done) is that node.children will be [] instead of None if there are no children. Therefore iterating over children will be a no-op instead of a TypeError.