[Erp5-report] r33408 leonardo - in /erp5/trunk/products/ERP5: Document/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Mar 4 22:29:40 CET 2010


Author: leonardo
Date: Thu Mar  4 22:29:38 2010
New Revision: 33408

URL: http://svn.erp5.org?rev=33408&view=rev
Log:
flush all ZODB caches when importing new synthetic modules, so cached objects don't behave as their old classes

Modified:
    erp5/trunk/products/ERP5/Document/BusinessTemplate.py
    erp5/trunk/products/ERP5/tests/testBusinessTemplate.py

Modified: erp5/trunk/products/ERP5/Document/BusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BusinessTemplate.py?rev=33408&r1=33407&r2=33408&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] Thu Mar  4 22:29:38 2010
@@ -3147,6 +3147,16 @@
             continue
           if self.local_file_importer_name is not None:
             globals()[self.local_file_importer_name](name)
+            # after any import, flush all ZODB caches to force a DB reload
+            # otherwise we could have objects trying to get commited while
+            # holding reference to a class that is no longer the same one as
+            # the class in its import location and pickle doesn't tolerate it.
+            # First we do a savepoint to dump dirty objects to temporary
+            # storage, so that all references to them can be freed.
+            transaction.savepoint(optimistic=True)
+            # Then we need to flush from all caches, not only the one from this
+            # connection
+            self.getPortalObject()._p_jar.db().cacheMinimize()
     else:
       BaseTemplateItem.install(self, context, trashbin, **kw)
       for id in self._archive.keys():

Modified: erp5/trunk/products/ERP5/tests/testBusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testBusinessTemplate.py?rev=33408&r1=33407&r2=33408&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] Thu Mar  4 22:29:38 2010
@@ -5988,6 +5988,14 @@
       template_tool = self.portal.portal_templates
       bt_path = os.path.join(os.path.dirname(__file__), 'test_data',
                              self._testMethodName)
+      # create a previously existing instance of the overriden document type
+      from Products.ERP5Type.Document.File import File
+      from Products.CMFDefault.File import File as BaseFile
+      self.portal._setObject('another_file', File('another_file'))
+      transaction.commit()
+      self.tic()
+      # check its class has not yet been overriden
+      self.assertTrue(isinstance(self.portal.another_file, BaseFile))
       for i in xrange(6):
         marker_list.append(i)
         gc.disable()
@@ -6001,6 +6009,9 @@
         self.assertEqual(self.portal.some_file.int_index, i)
         transaction.commit()
         self.tic()
+        # check the previously existing instance now behaves as the overriden
+        # class
+        self.assertFalse(isinstance(self.portal.another_file, BaseFile))
     finally:
       BaseTemplateItem.removeProperties = BaseTemplateItem_removeProperties
       SimpleItem._getCopy = SimpleItem_getCopy




More information about the Erp5-report mailing list