ZTUtils.SimpleTreeMaker creates trees that check security twice for everything

Bug #143944 reported by Jonathan Essex
2
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Low
Unassigned

Bug Description

(1) Invoke verbose security
(2) call hasChildren in a ZTUtils.SimpleTreeMaker
(3) call getChildren in a ZTUtils.SimpleTreeMaker

...and watch for double exceptions in the log every time we try to skip an unauthorised child. Apart from the performance issue, this appears to cause some erratic behaviour which I can't fully explain.

The cause is simple:

hasChildren in Tree.SimpleTreeMaker caches the result of getChildren
When hasChildren is invoked on ZTUtils.SimpleTreeMaker, getChildren is overriden by TreeSkipMixin. Hence it's the _filtered_ child list that gets cached.
Thus when getChildren on ZTUtils.SimpleTreeMaker is subsequenly called, the resulting child list is filtered twice.

The fix is to add an getCachedChildren() to Tree.SimpleTreeMaker which returns the cached results or None; then ZTUtils.SimpleTreeMaker.getChildren can return the cached results directly if available.

This is such a Classic multiple inheritance gotcha, it makes me want to go back to Java!

But if you ask me this there should be an abstract TreeMakerBase class with three subclasses, CachingTreeMaker, FilteredTreeMaker, and TreeMaker; CachingTreeMaker and FilteredTreeMaker should wrap a child TreeMaker which does the actual work and add the appropriate filtering/caching behaviour.

I'll happily refactor the code along these lines if anyone thinks it worthwhile.

Tags: bug zope
Changed in zope2:
importance: Medium → Low
status: New → Confirmed
Revision history for this message
Colin Watson (cjwatson) wrote :

The zope2 project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope2.

Changed in zope2:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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