From 09e025bdc485c3c3993aa52a96e67e1551676190 Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Wed, 7 Aug 2013 10:44:20 +0900
Subject: [PATCH] Make sure that objects created on bootstrap are committed
 before trying to load them from ZODB.

Because of recently added Component Tool, POSKeyError exception was raised
when trying to load it from ZODB during migration of Portal Type classes and
ZODB Property Sheets (PickleUpdater() in ERP5Site.migrateToPortalTypeClass),
so make sure that there is a commit before loading anything from ZODB.
---
 product/ERP5/ERP5Site.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/product/ERP5/ERP5Site.py b/product/ERP5/ERP5Site.py
index f8940ace45..0e5ec36f3c 100644
--- a/product/ERP5/ERP5Site.py
+++ b/product/ERP5/ERP5Site.py
@@ -44,6 +44,7 @@ from zLOG import LOG, INFO, WARNING, ERROR
 from string import join
 import os
 import warnings
+import transaction
 from App.config import getConfiguration
 MARKER = []
 
@@ -1600,6 +1601,10 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
   security.declareProtected(Permissions.ManagePortal,
                             'migrateToPortalTypeClass')
   def migrateToPortalTypeClass(self):
+    # PickleUpdater() will load objects from ZODB, but any objects created
+    # before must have been committed (otherwise POSKeyError is raised)
+    transaction.savepoint(optimistic=True)
+
     from Products.ERP5Type.dynamic.persistent_migration import PickleUpdater
     from Products.ERP5Type.Tool.BaseTool import BaseTool
     PickleUpdater(self)
-- 
2.30.9