From 94e73b43a71bd2244d1106c1e4945eba9bffbf7b Mon Sep 17 00:00:00 2001 From: Patrick Gerken Date: Wed, 21 Jul 2010 23:36:16 +0000 Subject: [PATCH] Catch TypeError in indexers if content can not be adapted Currently plone.app.discussion provides indexers for IContentish. In these it tries to adapt the content object to IDiscussion. But an IDiscussion Factory is only provided for IAnnotatable. The Criteria are IContentish but not IAnnotatable. Indexing them fails svn path=/plone.app.discussion/trunk/; revision=38182 --- CHANGES.txt | 6 ++++++ plone/app/discussion/catalog.py | 28 +++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9f427ad..885b89f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,12 @@ Changelog ========= +1.0b6 (unreleased) +------------------ + +* Catch Type errors in indexers if object can not be adapted to IDiscussion + [do3cc] + 1.0b5 (2010-07-16) ------------------ diff --git a/plone/app/discussion/catalog.py b/plone/app/discussion/catalog.py index c134ef4..062e91d 100644 --- a/plone/app/discussion/catalog.py +++ b/plone/app/discussion/catalog.py @@ -25,25 +25,39 @@ def total_comments(object): # Total number of comments on a conversation # Indexers won't work on old discussion items if object.meta_type != 'Discussion Item': - - conversation = IConversation(object) - return conversation.total_comments + try: + conversation = IConversation(object) + return conversation.total_comments + except TypeError: + # The item is contentish but nobody + # implemented an adapter for it + pass @indexer(IContentish, IZCatalog) def last_comment_date(object): # Date of the latest comment on a conversation # Indexers won't work on old discussion items if object.meta_type != 'Discussion Item': - conversation = IConversation(object) - return conversation.last_comment_date + try: + conversation = IConversation(object) + return conversation.last_comment_date + except TypeError: + # The item is contentish but nobody + # implemented an adapter for it + pass @indexer(IContentish, IZCatalog) def commentators(object): # List of commentators on a conversation # Indexers won't work on old discussion items if object.meta_type != 'Discussion Item': - conversation = IConversation(object) - return tuple(conversation.commentators.keys()) + try: + conversation = IConversation(object) + return tuple(conversation.commentators.keys()) + except TypeError: + # The item is contentish but nobody + # implemented an adapter for it + pass # Comment Indexers