diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py index b07b8429f2fbce03bcfd2def57225eb722a52567..a85709004202987f2b9fc1138506de07d1506058 100644 --- a/product/ERP5/Document/BusinessTemplate.py +++ b/product/ERP5/Document/BusinessTemplate.py @@ -3147,6 +3147,16 @@ class DocumentTemplateItem(BaseTemplateItem): 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(): diff --git a/product/ERP5/tests/testBusinessTemplate.py b/product/ERP5/tests/testBusinessTemplate.py index 4185fdf246049d8eabbdba80016f78d14aef4cfc..a1bca8ef8fca9ae8e3738e59e9c3bc30768dd532 100644 --- a/product/ERP5/tests/testBusinessTemplate.py +++ b/product/ERP5/tests/testBusinessTemplate.py @@ -5988,6 +5988,14 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): 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 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): 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