Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

AttributeError regarding NoneType in Catalog Results

by Alan Runyan last modified Dec 30, 2008 03:08 PM
While using .getObject() on a brain (the values returned by a catalog search result) a NoneType can be returned. This will cause an AttributeError in Zope 2.7; in Zope 2.8 it raises an exception either KeyError or AttributeError immedaitely.

If your catalog gets out of sync the paths in the catalog will not resolve. Prior to Zope 2.8 you would end up with a NoneType when you called .getObject on a brain. i.e.:

    for b in catalog(id='foo'):
        if b.getObject() is None:
            raise ValueError, 'This catalog entry is no longer in sync'

Typically you want to fix this and find out where in your application this is happening. There are a few ways of looking at it: for instance brains usually have a .getURL attribute that you can see where the location of the object is suppose to be.

There are numerous ways a brain could return None or an exception (in Zope 2.8) - for instance a ConflictError.