From 6830a0f8364d93edc77b62126bb5339a7b6ba690 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Mon, 9 Jul 2007 08:48:53 +0000
Subject: [PATCH] Prevent UIDs from being generated on temp objects by
 overriding the getUid accessor. Provide the Id as a fallback.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15168 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Base.py  | 8 ++++++++
 product/ERP5Type/Utils.py | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py
index 87ace6a85c..f07db115b3 100644
--- a/product/ERP5Type/Base.py
+++ b/product/ERP5Type/Base.py
@@ -2463,6 +2463,14 @@ class Base( CopyContainer,
   def _temp_setUid(self, value):
     self.uid = value # Required for Listbox so that no casting happens when we use TempBase to create new objects
 
+  def _temp_getUid(self):
+    try:
+      return getattr(aq_base(self), 'uid')
+    except AttributeError:
+      value = self.getId()
+      self.setUid(value)
+      return value
+
   def _temp_setTitle(self, value):
     """
     Required so that getProperty('title') will work on tempBase objects
diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py
index 4a8fc30260..f570875038 100644
--- a/product/ERP5Type/Utils.py
+++ b/product/ERP5Type/Utils.py
@@ -355,13 +355,13 @@ class TempDocumentConstructor(DocumentConstructor):
 
       # Replace some attributes.
       for name in ('isIndexable', 'reindexObject', 'recursiveReindexObject',
-                   'activate', 'setUid', 'setTitle', 'getTitle'):
+                   'activate', 'setUid', 'setTitle', 'getTitle', 'getUid'):
         setattr(TempDocument, name, getattr(klass, '_temp_%s' % name))
 
       # Make some methods public.
       for method_id in ('reindexObject', 'recursiveReindexObject',
                         'activate', 'setUid', 'setTitle', 'getTitle',
-                        'edit', 'setProperty'):
+                        'edit', 'setProperty', 'getUid'):
         setattr(TempDocument, '%s__roles__' % method_id, None)
 
       self.klass = TempDocument
-- 
2.30.9