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():
return getToolByName(context, 'my_catalog')
except AttributeError:
return None

catalog = _getCatalog()
if catalog:

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.


Post a Comment