Hi there,

in zope.app.catalog.attribute, there's the following functionality:

    def index_doc(self, docid, object):
        if self.interface is not None:
            object = self.interface(object, None)
            if object is None:
                return None

        value = getattr(object, self.field_name, None)
        if value is None:
            return None

        if self.field_callable:
            try:
                value = value()
            except:
                return None

        return super(AttributeIndex, self).index_doc(docid, value)

The following sequence I think leads to trouble:


        value = getattr(object, self.field_name, None)
        if value is None:
            return None

as this means attributes that do exist and have the value None would never be indexed (as index_doc() is never reached).

Instead, I'd suggest the following code:

        try:
            value = getattr(object, self.field_name)
        except AttributeError:
            return None

or alternatively if for some reason getattr() with a default is preferred (though I suspect the exception approach is slightly faster):

# module level
NotFound = object()

        value = getattr(object, self.field_name, NotFound)
        if value is NotFound:
             return None

If this is indeed decided to be a bug, is it okay if I check in a fix for this? I'll try to devise a test of course.

Regards,

Martijn
_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to