Thomas Guettler wrote:
I know. __setstate__ is what I called "implicit update". But AFAIK objects which are already in memory don't get updated until the next time they get unpickeled. That's why I prefere a explicit update. I called this method refresh() in my python product.
I agree, it's a good way to do it. I do think a name more unique then refresh is good though, because then you can simply traverse the hierarchy and call the upgrade method if it exists. I also make it a habit of letting any upgrade method set a version attribute on the object when it upgrades. It should also return something useful, like information of if it actually did an upgrade or not. Like this: security.declarePrivate('Upgrade Objets', 'UpgradeObjectVersion') def UpgradeObjectVersion(self): """Upgrades the object to new versions""" # Check if upgrade is necessary: if hasattr(self, '_object_version') and \ self._object_version == '1.1': return 0 #No upgrade # Upgrade if not hasattr(self, "birthday"): self.birthday=0 # Set version and return success self._object_version = '1.1' return 1 #Yup, upgraded [Although in this specific case, I would not check for the _object_version to determine if it should be upgraded, I would check for the birthday attribute. Ah, well, details... :) ].