[CMF-checkins] SVN: CMF/branches/2.1/CMFDefault/ -
CMFDefault.DiscussionTool: Prevent an exception in edge cases
Jens Vagelpohl
jens at dataflake.org
Sun Nov 18 17:51:13 EST 2007
Log message for revision 81923:
- 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.1/CMFDefault/DiscussionTool.py
U CMF/branches/2.1/CMFDefault/tests/test_DiscussionTool.py
-=-
Modified: CMF/branches/2.1/CMFDefault/DiscussionTool.py
===================================================================
--- CMF/branches/2.1/CMFDefault/DiscussionTool.py 2007-11-18 22:50:54 UTC (rev 81922)
+++ CMF/branches/2.1/CMFDefault/DiscussionTool.py 2007-11-18 22:51:13 UTC (rev 81923)
@@ -78,8 +78,13 @@
raise AccessControl_Unauthorized
if allowDiscussion is None or allowDiscussion == 'None':
- if getattr( aq_base(content), 'allow_discussion', _marker) is not _marker:
- del content.allow_discussion
+ disc_flag = getattr(aq_base(content), 'allow_discussion', _marker)
+ if disc_flag is not _marker:
+ 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.1/CMFDefault/tests/test_DiscussionTool.py
===================================================================
--- CMF/branches/2.1/CMFDefault/tests/test_DiscussionTool.py 2007-11-18 22:50:54 UTC (rev 81922)
+++ CMF/branches/2.1/CMFDefault/tests/test_DiscussionTool.py 2007-11-18 22:51:13 UTC (rev 81923)
@@ -77,6 +77,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