From 51cdca82d2db42fa4b7209b08ed6f1ed60c00501 Mon Sep 17 00:00:00 2001
From: Yoshinori Okuji <yo@nexedi.com>
Date: Mon, 27 Sep 2010 08:13:46 +0000
Subject: [PATCH] Create a temp object through type information, instead of
 making a hack inside asContext. This fixes a bug that the return value of
 asContext is not a temp object.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38650 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Base.py | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py
index 4b62796bb5..cb4d02f994 100644
--- a/product/ERP5Type/Base.py
+++ b/product/ERP5Type/Base.py
@@ -2792,14 +2792,17 @@ class Base( CopyContainer,
     ex : joe_person = person_module.bob_person.asContext(first_name='Joe')
     """
     if context is None:
-      # Make a copy
-      klass = self.__class__
-      try:
-        context = klass(self.getId())
-      except TypeError:
-        # If __init__ does not take the id argument, the class is probably
-        # a tool, and the id is predifined and immutable.
-        context = klass()
+      pt = self._getTypesTool()
+      type_info = pt.getTypeInfo(self.getPortalType())
+      if type_info is None:
+        raise ValueError('No such content type: %s' % portal_type)
+
+      context = type_info.constructInstance(
+              container=self.getParentValue(),
+              id=self.getId(),
+              temp_object=True,
+              is_indexable=False)
+
       context.__dict__.update(self.__dict__)
       # Copy REQUEST properties to self
       if REQUEST is not None:
@@ -2811,13 +2814,7 @@ class Base( CopyContainer,
             setattr(context, k, REQUEST[k])
       # Define local properties
       context.__dict__.update(kw)
-      # Make it a temp content
-      temp_object = TempBase(self.getId())
-      for k in ('isIndexable', 'isTempDocument', 'reindexObject',
-                'recursiveReindexObject', 'activate', 'setUid'):
-        setattr(context, k, getattr(temp_object, k))
-      # Return result
-      return context.__of__(self.aq_parent)
+      return context
     else:
       return context.asContext(REQUEST=REQUEST, **kw)
 
-- 
2.30.9