This is a really awkward way to write the function. You don't need the else block. Just save the result of the first access of `item.parent_id` and do the test after that:

```
try:
    parent_id = item.parent_id
except AttributeError:
    return True

return parent_id is not None