From 1fc6d538bf28b84f7ceb79cd05fcf24335fc97e5 Mon Sep 17 00:00:00 2001
From: Nicolas Dumazet <nicolas.dumazet@nexedi.com>
Date: Thu, 11 Nov 2010 02:07:06 +0000
Subject: [PATCH] Be more permissive if neither factory_method_id nor
 type_class are set.

We already try to infer/guess the Document type if portal type object does not
exist: it's logical to do the same if portal type exists but is misconfigured,
or just way too old.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40200 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/dynamic/portal_type_class.py | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/product/ERP5Type/dynamic/portal_type_class.py b/product/ERP5Type/dynamic/portal_type_class.py
index 95f25ffc38..c75f846157 100644
--- a/product/ERP5Type/dynamic/portal_type_class.py
+++ b/product/ERP5Type/dynamic/portal_type_class.py
@@ -104,11 +104,22 @@ def generatePortalTypeClass(portal_type_name):
   site = getSite()
 
   accessor_holder_list = []
+  type_class = None
 
   # Do not use __getitem__ (or _getOb) because portal_type may exist in a
   # type provider other than Types Tool.
   portal_type = getattr(site.portal_types, portal_type_name, None)
-  if portal_type is None:
+  if portal_type is not None:
+    # type_class has a compatibility getter that should return
+    # something even if the field is not set (i.e. Base Type object
+    # was not migrated yet). It only works if factory_method_id is set.
+    type_class = portal_type.getTypeClass()
+    mixin_list = portal_type.getTypeMixinList()
+    interface_list = portal_type.getTypeInterfaceList()
+
+  # But if neither factory_init_method_id nor type_class are set on
+  # the portal type, we have to try to guess, for compatibility
+  if type_class is None:
     # Try to figure out a coresponding document class from the document side.
     # This can happen when calling newTempAmount for instance:
     #  Amount has no corresponding Base Type and will never have one
@@ -117,13 +128,6 @@ def generatePortalTypeClass(portal_type_name):
     type_class = portal_type_name.replace(' ', '')
     mixin_list = []
     interface_list = []
-  else:
-    # type_class has a compatibility getter that should return
-    # something even if the field is not set (i.e. Base Type object
-    # was not migrated yet)
-    type_class = portal_type.getTypeClass()
-    mixin_list = portal_type.getTypeMixinList()
-    interface_list = portal_type.getTypeInterfaceList()
 
   type_class_path = document_class_registry.get(type_class)
   if type_class_path is None:
-- 
2.30.9