[CMF-checkins] SVN: CMF/branches/2.0/CMFDefault/ - CMFDefault.DiscussionTool: Prevent an exception in edge cases

Jens Vagelpohl jens at dataflake.org
Sun Nov 18 17:51:31 EST 2007


Log message for revision 81924:
  - CMFDefault.DiscussionTool: Prevent an exception in edge cases
    where the flag to allow discussions only exists at class level.
    (https://bugs.launchpad.net/zope-cmf/+bug/162532)
  

Changed:
  U   CMF/branches/2.0/CMFDefault/DiscussionTool.py
  U   CMF/branches/2.0/CMFDefault/tests/test_DiscussionTool.py

-=-
Modified: CMF/branches/2.0/CMFDefault/DiscussionTool.py
===================================================================
--- CMF/branches/2.0/CMFDefault/DiscussionTool.py	2007-11-18 22:51:13 UTC (rev 81923)
+++ CMF/branches/2.0/CMFDefault/DiscussionTool.py	2007-11-18 22:51:31 UTC (rev 81924)
@@ -79,7 +79,11 @@
 
         if allowDiscussion is None or allowDiscussion == 'None':
             if hasattr( aq_base(content), 'allow_discussion'):
-                del content.allow_discussion
+                try:
+                    del content.allow_discussion
+                except AttributeError:
+                    # https://bugs.launchpad.net/zope-cmf/+bug/162532
+                    pass
         else:
             content.allow_discussion = bool(allowDiscussion)
 

Modified: CMF/branches/2.0/CMFDefault/tests/test_DiscussionTool.py
===================================================================
--- CMF/branches/2.0/CMFDefault/tests/test_DiscussionTool.py	2007-11-18 22:51:13 UTC (rev 81923)
+++ CMF/branches/2.0/CMFDefault/tests/test_DiscussionTool.py	2007-11-18 22:51:31 UTC (rev 81924)
@@ -73,6 +73,18 @@
         dtool.overrideDiscussionFor(foo, None)
         self.failIf( hasattr(foo.aq_base, 'allow_discussion') )
 
+        # https://bugs.launchpad.net/zope-cmf/+bug/162532: Don't break
+        # if allow_discussion only exists at the class level
+        class DummyContent:
+            allow_discussion = False
+            def getId(self): return 'dummy'
+
+        dummy = DummyContent()
+        try:
+            dtool.overrideDiscussionFor(dummy, None)
+        except AttributeError:
+            self.fail('Launchpad issue 162532: AttributeError raised')
+
     def test_isDiscussionAllowedFor(self):
         # Test for Collector issue #398 (allow_discussion wrongly
         # acquired and used from parent)



More information about the CMF-checkins mailing list