zope.app.tree.node error in hasChildren()

Bug #264629 reported by Dragos Petre
2
Affects Status Importance Assigned to Milestone
Zope 3
Won't Fix
Undecided
Unassigned
zope.app.tree
New
Undecided
Unassigned

Bug Description

The hasChildren() method of zope.app.tree.node.Node is returning True even when the Node's children are all filtered out. This causes the navigation macro to display an expansion symbol (+ or -) to the left of a folder whose items are filtered out but when expanded, no children are displayed (which is correct).

The below test case, if added to the test_node.py module in the zope.app.tree.tests package, exemplifies the issue (please note that the patch in https://bugs.launchpad.net/bugs/264614 should be applied to the test module first):

    def test_filter(self):
        #An empty filter would filter all content out
        empty_filter = FilterByObject()
        filtered_root=Node(self.root_obj,filter=empty_filter)
        children = [node.context for node in filtered_root.getChildNodes()]
        expected = []
        self.assertEqual(children,expected)
        self.failIf(filtered_root.hasChildren())

The test fails on the last assertion because the hasChildren() method delegates to the synonymous method of the adapter, which is NOT filter aware.

A rough way around it is to change the hasChildren() method in node.py to return the length of getChildNodes() if the Node object has a filter defined. More efficient ways could probably be implemented and any comment on it would be appreciated.

Best regards,
Dragos.

Revision history for this message
Dragos Petre (drpetrea) wrote :
Changed in zope3:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.