[Zope-dev] ugh. bug(?) in ZCatalog.ZopeFindAndApply
Anthony Baxter
anthony@interlink.com.au
Thu, 16 Dec 1999 20:29:53 +1100
ooo, this has been an annoying one to track down.
When ZCatalog's ZopeFindAndApply is called, it looks at
container.aq_base.objectItems() to list the objects in a
container, then indexes them. This means that if you're
indexing an attribute that's acquired from higher up the
chain than the immediate enclosing folder, it won't get
picked up. It _will_ when you call manage_catalogReIndex,
as it does a resolve_url of the object. This caused much
confusion for me, as the Catalog bug I was seeing would
be there sometimes and not others, depending on whether
a reindex had happened.
Two possible fixes here:
First is to force a resolve_url before indexing.
Second is to index the object in the initial acquisition context
(and pass the correct object to the recursive call)
Not sure which is the better fix - both work for me. The second is
probably cheaper, and "more correct"
Note that there's another fix needed for this to work that's in
the collector - there's a call to 'find' that should be 'string.find'
(line numbers may be off - there's other magic stuff in my local copy.)
Can anyone else confirm that this is an appropriate approach? Or
is ZopeFindAndApply meant to act this way?
ta,
Anthony
RCS file: /cvs-repository/Zope2/lib/python/Products/ZCatalog/ZCatalog.py,v
retrieving revision 1.42
diff -u -r1.42 ZCatalog.py
--- ZCatalog.py 1999/11/05 18:58:54 1.42
+++ ZCatalog.py 1999/12/16 07:39:38
@@ -533,7 +559,14 @@
)
):
if apply_func:
- apply_func(ob, (apply_path+'/'+p))
+ # needed because earlier we retrieved
+ # container.aq_base.objectItems, otherwise
+ # we don't see anything acquired from more
+ # than one acquisition level higher
+ if REQUEST:
+ ptmp = apply_path+'/'+p
+ ob = self.resolve_url(ptmp, REQUEST)
+ apply_func(ob, (ptmp))
else:
add_result((p, ob))
dflag=0
RCS file: /cvs-repository/Zope2/lib/python/Products/ZCatalog/ZCatalog.py,v
retrieving revision 1.42
diff -u -r1.42 ZCatalog.py
--- ZCatalog.py 1999/11/05 18:58:54 1.42
+++ ZCatalog.py 1999/12/16 07:39:38
@@ -532,14 +558,16 @@
role_match(ob, obj_permission, obj_roles)
)
):
+ ob_real = getattr(obj, id)
if apply_func:
- apply_func(ob, (apply_path+'/'+p))
+ apply_func(ob_real, (apply_path+'/'+p))
else:
- add_result((p, ob))
+ add_result((p, ob_real))
dflag=0
if search_sub and hasattr(bs, 'objectItems'):
- self.ZopeFindAndApply(ob, obj_ids, obj_metatypes,
+ ob_real = getattr(obj, id)
+ self.ZopeFindAndApply(ob_real, obj_ids, obj_metatypes,
obj_searchterm, obj_expr,
obj_mtime, obj_mspec,
obj_permission, obj_roles,