[Erp5-report] r31791 jm - in /erp5/trunk/products: ERP5/Document/ ERP5Type/tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Sun Jan 17 23:20:23 CET 2010


Author: jm
Date: Sun Jan 17 23:20:23 2010
New Revision: 31791

URL: http://svn.erp5.org?rev=31791&view=rev
Log:
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].

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

Modified: erp5/trunk/products/ERP5/Document/BusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BusinessTemplate.py?rev=31791&r1=31790&r2=31791&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] Sun Jan 17 23:20:23 2010
@@ -5611,15 +5611,22 @@
       # Create temporary modules/classes for classes defined by this BT.
       # This is required if the BT contains instances of one of these classes.
       module_id_list = []
+      instance_oid_list = []
       for template_type in ('Constraint', 'Document', 'PropertySheet'):
         for template_id in getattr(self,
                                    'getTemplate%sIdList' % template_type)():
           module_id = 'Products.ERP5Type.%s.%s' % (template_type, template_id)
-          if module_id not in sys.modules:
-            module_id_list.append(module_id)
-            sys.modules[module_id] = module = imp.new_module(module_id)
-            module.SimpleItem = SimpleItem.SimpleItem
-            exec "class %s(SimpleItem): pass" % template_id in module.__dict__
+          module_id_list.append(module_id)
+          # Always redefine the module, so that 'instance_oid_list' contains
+          # the full list of oid to remove from pickle cache.
+          sys.modules[module_id] = module = imp.new_module(module_id)
+          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:
         getattr(self, item_name).importFile(bta)
@@ -5628,6 +5635,14 @@
       # (during the installation).
       for module_id in module_id_list:
         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):
       """Return list of items in business template

Modified: erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py?rev=31791&r1=31790&r2=31791&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py [utf8] Sun Jan 17 23:20:23 2010
@@ -11,7 +11,7 @@
 import errno
 import md5
 import os
-#import random # XXX
+import random
 import re
 import socket
 import sys
@@ -753,7 +753,6 @@
       """Starts an HTTP ZServer thread."""
       from Testing.ZopeTestCase import threadutils, utils
       if utils._Z2HOST is None:
-        import random
         randint = random.Random(hash(os.environ['INSTANCE_HOME'])).randint
         def zserverRunner():
           try:




More information about the Erp5-report mailing list