[ZCM] [ZC] 2351/ 1 Request "ZTUtils.SimpleTreeMaker creates trees that check security twice for everything"

"Collector: Zope Bugs, Features, and Patches ..." <[email protected]> Fri, 31 Aug 2007 01:37:45 -0400
Newsgroups gmane.comp.web.zope.devel.collector-monitor
Message-ID <[email protected]>
Issue #2351 Update (Request) "ZTUtils.SimpleTreeMaker creates trees that check security twice for everything"
 Status Pending, Zope/bug medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/2351

==============================================================
= Request - Entry #1 by jonathanessex on Aug 31, 2007 1:37 am


(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.
  
  

==============================================================