Log message for revision 113523: use ZODB Broken class to allow access to state
Changed: U Zope/branches/gotcha-LP143531/src/OFS/Uninstalled.py U Zope/branches/gotcha-LP143531/src/OFS/tests/test_Uninstalled.py -=- Modified: Zope/branches/gotcha-LP143531/src/OFS/Uninstalled.py =================================================================== --- Zope/branches/gotcha-LP143531/src/OFS/Uninstalled.py 2010-06-16 12:10:05 UTC (rev 113522) +++ Zope/branches/gotcha-LP143531/src/OFS/Uninstalled.py 2010-06-16 12:12:38 UTC (rev 113523) @@ -22,12 +22,14 @@ from App.special_dtml import DTMLFile from OFS.SimpleItem import Item from Persistence import Overridable +from ZODB.broken import Broken as ZODB_Broken +from ZODB.broken import persistentBroken broken_klasses={} broken_klasses_lock = allocate_lock() LOG = getLogger('OFS.Uninstalled') -class BrokenClass(Explicit, Item, Overridable): +class BrokenClass(ZODB_Broken, Explicit, Item, Overridable): _p_changed=0 meta_type='Broken Because Product is Gone' icon='p_/broken' @@ -37,12 +39,6 @@ manage_page_header = Acquired manage_page_footer = Acquired - def __getstate__(self): - raise SystemError, ( - """This object was originally created by a product that - is no longer installed. It cannot be updated. - (%s)""" % repr(self)) - def __getattr__(self, name): if name[:3]=='_p_': return BrokenClass.inheritedAttribute('__getattr__')(self, name) @@ -74,6 +70,7 @@ klass.info=( 'This object\'s class was %s in module %s.' % (klass.__name__, klass.__module__)) + klass = persistentBroken(klass) LOG.warning('Could not import class %s ' 'from module %s' % (`klass.__name__`, `klass.__module__`)) finally: Modified: Zope/branches/gotcha-LP143531/src/OFS/tests/test_Uninstalled.py =================================================================== --- Zope/branches/gotcha-LP143531/src/OFS/tests/test_Uninstalled.py 2010-06-16 12:10:05 UTC (rev 113522) +++ Zope/branches/gotcha-LP143531/src/OFS/tests/test_Uninstalled.py 2010-06-16 12:12:38 UTC (rev 113523) @@ -77,24 +77,8 @@ self.assertEqual(klass.__module__, 'Products.MyProduct.MyClass') self.assertEqual(klass.product_name, 'MyProduct') - def test_Broken_instance___getstate___raises_useful_exception(self): - # see http://www.zope.org/Collectors/Zope/2157 - from OFS.Uninstalled import Broken - from OFS.Uninstalled import BrokenClass - OID = '\x01' * 8 - - inst = Broken(self, OID, ('Products.MyProduct.MyClass', 'MyClass')) - - try: - dict = inst.__getstate__() - except SystemError, e: - self.failUnless('MyClass' in str(e), str(e)) - else: - self.fail("'__getstate__' didn't raise SystemError!") - def test_Broken_instance___getattr___allows_persistence_attrs(self): from OFS.Uninstalled import Broken - from OFS.Uninstalled import BrokenClass OID = '\x01' * 8 PERSISTENCE_ATTRS = ["_p_changed", "_p_jar", @@ -119,6 +103,13 @@ for meth_name in PERSISTENCE_METHODS: meth = getattr(inst, meth_name) # doesn't raise + def test_Broken_instance___getstate___gives_access_to_its_state(self): + from OFS.Uninstalled import Broken + OID = '\x01' * 8 + inst = Broken(self, OID, ('Products.MyProduct.MyClass', 'MyClass')) + inst.__setstate__({'x': 1}) + self.assertEqual(inst.__getstate__(), {'x': 1}) + def test_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(TestsOfBroken)) @@ -129,4 +120,3 @@ if __name__ == '__main__': main() - _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org https://mail.zope.org/mailman/listinfo/zope-checkins