Luca Olivetti wrote:
Luca Olivetti wrote:
2) the content of the script is
attr=getattr(context.aq_explicit,'yourattributename')
hmmm, change that to
attr=getattr(context.aq_explicit,'yourattributename',())
if it is to be picked up by a keyword index
if callable(attr): attr=attr() return attr
I stumbled into another problem: the method is useable for indexes but not for metadata. I digged into the source of ZCatalog and I saw that's because Zcatalog first calls recordify (see Catalog.py) on the object which uses MV (from Missing) to indicate a missing attribute, while each plugin index uses a different method to identify a missing attribute (for example, UnIndex.py defines an internal _merker as []). So if my method uses attr=getattr(context.aq_explicit,'myattribute') it will tipically work in a plugin index because it's wrapped in a try except block, but will not work with metadata since there's no try/except there. I can use attr=getattr(context.aq_explicit,'myattribute',MV) (in an external method, a python script cannot use Missing) but that, while giving the correct result to recordify, will still index the object since the plugin index is expecting another value to indicate a missing attribute. If it were possible to import an attribute starting with _ doing from Products.PluginIndexes.common.Unindex import _merker attr=getattr(context.aq_explicit,'myattribute',_merker) will give the correct result for a fieldIndex but would use the wrong metadata for other indexes. I may be wrong but I think that the inconsistency between the value used by the catalog and the various plugin indexes to indicate a missing value should be fixed, for example they could all import MV from Missing like Catalog.py does. Should I file this into the collector or there is another reason I don't know for these inconsistencies? I can change it myself in my local zope (currently 2.6.1b1) but there's no point in doing it if the next release will overwrite my changes. For the time being, do you see another solution besides writing two methods (one for metadata and the other for indexes)? TIA -- Luca Olivetti Wetron Automatización S.A. http://www.wetron.es/ Tel. +34 93 5883004 Fax +34 93 5883007