Commit 13b0fb9a authored by Julien Muchembled's avatar Julien Muchembled

Fix support of BT containing instances of classes defined by the BT itself.

This fixes [28422] and testBPMEvaluation (PicklingError exceptions).
This reverts useless [30411].
It also allows to revert [31213].

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31791 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f8db9024
...@@ -5611,15 +5611,22 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5611,15 +5611,22 @@ Business Template is a set of definitions, such as skins, portal types and categ
# Create temporary modules/classes for classes defined by this BT. # Create temporary modules/classes for classes defined by this BT.
# This is required if the BT contains instances of one of these classes. # This is required if the BT contains instances of one of these classes.
module_id_list = [] module_id_list = []
instance_oid_list = []
for template_type in ('Constraint', 'Document', 'PropertySheet'): for template_type in ('Constraint', 'Document', 'PropertySheet'):
for template_id in getattr(self, for template_id in getattr(self,
'getTemplate%sIdList' % template_type)(): 'getTemplate%sIdList' % template_type)():
module_id = 'Products.ERP5Type.%s.%s' % (template_type, template_id) module_id = 'Products.ERP5Type.%s.%s' % (template_type, template_id)
if module_id not in sys.modules: module_id_list.append(module_id)
module_id_list.append(module_id) # Always redefine the module, so that 'instance_oid_list' contains
sys.modules[module_id] = module = imp.new_module(module_id) # the full list of oid to remove from pickle cache.
module.SimpleItem = SimpleItem.SimpleItem sys.modules[module_id] = module = imp.new_module(module_id)
exec "class %s(SimpleItem): pass" % template_id in module.__dict__ module.SimpleItem = SimpleItem.SimpleItem
module.instance_oid_list = instance_oid_list
exec """class %s(SimpleItem):
def __setstate__(self, state):
instance_oid_list.append(self._p_oid)
return SimpleItem.__setstate__(self, state)""" % template_id \
in module.__dict__
for item_name in self._item_name_list: for item_name in self._item_name_list:
getattr(self, item_name).importFile(bta) getattr(self, item_name).importFile(bta)
...@@ -5628,6 +5635,14 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5628,6 +5635,14 @@ Business Template is a set of definitions, such as skins, portal types and categ
# (during the installation). # (during the installation).
for module_id in module_id_list: for module_id in module_id_list:
del sys.modules[module_id] del sys.modules[module_id]
# Remove from pickle cache all objects whose classes are temporary
# (= defined by this BT). This forces to reload these objects on next
# access, with the correct classes.
# Invalidation is forced using __delitem__ instead of invalidate.
if instance_oid_list:
pickle_cache = self.getPortalObject()._p_jar._cache
for oid in instance_oid_list:
del pickle_cache[oid]
def getItemsList(self): def getItemsList(self):
"""Return list of items in business template """Return list of items in business template
......
...@@ -11,7 +11,7 @@ import base64 ...@@ -11,7 +11,7 @@ import base64
import errno import errno
import md5 import md5
import os import os
#import random # XXX import random
import re import re
import socket import socket
import sys import sys
...@@ -753,7 +753,6 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase): ...@@ -753,7 +753,6 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase):
"""Starts an HTTP ZServer thread.""" """Starts an HTTP ZServer thread."""
from Testing.ZopeTestCase import threadutils, utils from Testing.ZopeTestCase import threadutils, utils
if utils._Z2HOST is None: if utils._Z2HOST is None:
import random
randint = random.Random(hash(os.environ['INSTANCE_HOME'])).randint randint = random.Random(hash(os.environ['INSTANCE_HOME'])).randint
def zserverRunner(): def zserverRunner():
try: try:
......
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