[Zope3-Users] adding indexes in a __init__ method

Lorenzo Gil Sanchez lgs at sicem.biz
Tue Jul 25 05:26:09 EDT 2006


Hi,

I have a special Folder content. When an instance of this class is
created I want to create a catalog and an index in its __init__ method.
Something like:

class FilterableContainer(BTreeContainer):

    implements(IFilterableContainer)

    def __init__(self):
        super(FilterableContainer, self).__init__()
        self._catalog = LocalCatalog()
        self._catalog['attr1'] = FieldIndex(field_name='attr1')

where LocalCatalog is a subclass of Catalog that only indexes objects
that belong to its parent.

The problem arises when I add my FieldIndex to my internal catalog. Some
events are triggered and at the end I got this exception:

  File "/opt/Zope-3.2.1/lib/python/zope/app/keyreference/persistent.py",
line 41, in __init__
    raise zope.app.keyreference.interfaces.NotYet(object)
NotYet: <zope.app.catalog.field.FieldIndex object at 0x2aaab3609b90>


It happens because the key reference adaptor to Persistent thinks my
FieldIndex object is already stored in the database, which is not the
case.

Anybody knows how should I add an index to my catalog in the __init__
method?

Thanks in advance

Lorenzo



More information about the Zope3-users mailing list