From 49f5ed1309c55ab32f18999442f1a011332fcd37 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Wed, 5 Oct 2011 08:42:49 -0400 Subject: [PATCH] make upgrade process more forgiving: don't call InitTransient on objects until everything's upgraded --- tpers.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tpers.py b/tpers.py index cfe4cb7..b7c4c39 100644 --- a/tpers.py +++ b/tpers.py @@ -113,8 +113,7 @@ class TPrs(object): self._fWriteToPersistent = True if self._versionCurr != self._version: Odb.rgtprsToUpgrade.append(self) - with self.SetTransiently(): - self.InitTransient() + Odb.rgtprsToInit.append(self) def _Upgrade(self): self.UpgradeFrom(self._versionCurr) self._versionCurr = self._version @@ -128,6 +127,7 @@ class Odb(object): @classmethod def Load(cls, fn): cls.rgtprsToUpgrade = [] + cls.rgtprsToInit = [] try: with open(fn, "r") as fl: tprs = cPickle.load(fl) @@ -135,13 +135,17 @@ class Odb(object): print "error unpickling:", e traceback.print_exc() return None + for tprsToUpgrade in cls.rgtprsToUpgrade: + tprsToUpgrade._Upgrade() + for tprsToInit in cls.rgtprsToInit: + with tprsToInit.SetTransiently(): + tprsToInit.InitTransient() if len(cls.rgtprsToUpgrade) > 0: - for tprsToUpgrade in cls.rgtprsToUpgrade: - tprsToUpgrade._Upgrade() fnUpgraded = fn + ".upgraded" Odb.Save(tprs, fnUpgraded) tprs = Odb.Load(fnUpgraded) cls.rgtprsToUpgrade = None + cls.rgtprsToInit = None return tprs clsList = list