[Zope] stopping indexing of acquired attributes
Luca Olivetti
luca@wetron.es
Tue, 31 Dec 2002 13:45:50 +0100
Chris Withers wrote:
> Luca Olivetti wrote:
>
>> 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 []).
>
>
> Why would hypothesise that the real problem is that adding stuff to
> indexes ignores AttributeError's and KeyError's which storing it as
> metadata doesn't, which it should.
Yes, this is the quick fix I finally adopted:
--- Catalog.py.orig Tue Dec 31 10:25:44 2002
+++ Catalog.py Tue Dec 31 10:39:28 2002
@@ -400,8 +400,11 @@
record = []
# the unique id is allways the first element
for x in self.names:
- attr=getattr(object, x, MV)
- if(attr is not MV and callable(attr)): attr=attr()
+ try:
+ attr=getattr(object, x, MV)
+ if(attr is not MV and callable(attr)): attr=attr()
+ except AttributeError:
+ attr=MV
record.append(attr)
return tuple(record)
>
>> 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.
>
>
> So put one in yourself ;-) (well, something that works the same...)
>
> attr=getattr(context.aq_explicit,'myattribute',None)
That was the first thing I tried but it didn't (aesthetically) please
me: *all* object would be catalogged (it not the same None than the
missing value each plugin index and metadata uses).
Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004 Fax +34 93 5883007