Wrong indexing content

Some days ago we was experienced a strange behavior that I think could be useuful to share, and have some suggestions by others.

This is the story semplified: suppose to have a Catalog's index named "foo" and to have a folderish content named "bar" that not implements an indexer "foo" nor has an attribute "foo".

Suppose to add into "bar" another content and naming that content "foo".

Now, whenever "bar" will be reindexed, the Catalog, during "foo" (the index) indexing, will found a "foo" attribute (the other content) callable (the default view of "foo"). So the Catalog will call the default view of the content "foo" thinking that as the index "foo" of "bar"...

This is not only an obvious wrong index data, but also a big penality in term of performances (calling the view could be very expensive).

There are a lot of other variants for this story, with Catalog's metadata instead of index, or acquisition instead of direct containment, ...

Personally I don't have a simple solution for that, I think that probably catalog don't ever need to getattr another object during indexing.

My "quick and dirty" solution for now wll be to monkeypatching Catalog's safe_call function (https://github.com/zopefoundation/Products.ZCatalog/blob/3.0.x/src/Products/ZCatalog/Catalog.py#L43) to return as unsafe the default view of a content, but I think someone here could have a better solution.

Any hints or comments?

AFAIK this is a feature (indexing anything with the required name that could be acquired / traversed). This allows defining new indexes with custom indexers TTW (custom indexers could be implemented e.g. with scripts in portal_skins/custom).

The simplest way to disable that behavior for custom indexers defined in add-ons packages is to always register a such dummy plone.indexer for pure zope.interface.Interface that only raises AttributeError. (Indexer adapter lookup is done before attribute lookup and if adapter is found but raises AttributeError indexer skips the object and moves on.)

1 Like

We've used this feature in the past. One of the only times aquisition has come in useful.

But I agree its probably not the right way of enabling TTW indexes due to the problems highlighted. @datakurre it would be nice if themingfragments or something similar could have a solution here?