flush all ZODB caches when importing new synthetic modules, so cached objects...

flush all ZODB caches when importing new synthetic modules, so cached objects don't behave as their old classes

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33408 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a38c59c9
......@@ -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():
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment