Fun Fact of the Day

So, let's say you're trying to catalog an object in a ZCatalog, and for important reasons irrelevant to the instant case you have code similar to the following:
    from Products.CMFCore.utils import getToolByName

def _getCatalog():
try:
return getToolByName(context, 'my_catalog')
except AttributeError:
return None

catalog = _getCatalog()
if catalog:
catalog.catalog_object(myobject)

I sure assumed that would work. Not so! If the catalog is empty, bool(catalog)==False. You have to do:

if catalog is not None:

And there's an hour I'll never get back.

0 comments

Post a Comment