[Erp5-report] r31801 jm - /erp5/trunk/products/ERP5/Document/BusinessTemplate.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Jan 18 13:57:18 CET 2010


Author: jm
Date: Mon Jan 18 13:57:17 2010
New Revision: 31801

URL: http://svn.erp5.org?rev=31801&view=rev
Log:
Fix 2 regressions caused by [31791]

* Restore overridden modules, for 2 reasons:
  - The user may choose to not install the new module.
  - Modules in BT may import from ERP5Type.Document the classes they override
    (although I am sure it is good practice).
* Check existence of oid in pickle cache before deleting it, because it may
  have been already removed automatically.

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

Modified: erp5/trunk/products/ERP5/Document/BusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BusinessTemplate.py?rev=31801&r1=31800&r2=31801&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] Mon Jan 18 13:57:17 2010
@@ -5610,13 +5610,13 @@
 
       # 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 = []
+      orig_module_dict = {}
       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)
-          module_id_list.append(module_id)
+          orig_module_dict[module_id] = sys.modules.get(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)
@@ -5633,8 +5633,12 @@
 
       # Remove temporary modules created above to allow import of real modules
       # (during the installation).
-      for module_id in module_id_list:
-        del sys.modules[module_id]
+      # Restore original module if any, in case the new one is not installed.
+      for module_id, module in orig_module_dict.iteritems():
+        if module is None:
+          del sys.modules[module_id]
+        else:
+          sys.modules[module_id] = module
       # 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.
@@ -5642,7 +5646,8 @@
       if instance_oid_list:
         pickle_cache = self.getPortalObject()._p_jar._cache
         for oid in instance_oid_list:
-          del pickle_cache[oid]
+          if pickle_cache.get(oid) is not None:
+            del pickle_cache[oid]
 
     def getItemsList(self):
       """Return list of items in business template




More information about the Erp5-report mailing list