Antonio Beamud Montero wrote:
Long time ago I started to develop a big product, it's under development now, but with some stable releases in a client. My problem is that new releases of a Product adds new attributes and when I upgrade de Product, I need to create another instance and recreate all the system, because old instances in the zobd haven't that attributes... Now, it's no problem, but when this system is in production, with hundred of objects... buff... How I can solve this problem...?
#################### # put this external method in the root new_default_value = '' objects = self.ZopeFind(self, obj_metatypes=['big_product'], search_sub=1) for path, obj in objects: obj.newAttr = new_default_value #################### If you are updating a lot of objects you should probably do partial commits along the way or it can be rather slow. You can do it like that new_default_value = '' objects = self.ZopeFind(self, obj_metatypes=['big_product'], search_sub=1) transaction = get_transaction() # magical built in function i = 0 for path, obj in objects: obj.newAttr = new_default_value if i != 0 and not i % 100: # partial commit for ever 100 transaction.commit(1) i += 1 #################### # naturally you can generalize it a bit def update(meta_type, updater): """ Finds all the objects, sub-commits and calls the updater function on every object """ objects = self.ZopeFind(self, obj_metatypes=[meta_type], search_sub=1) transaction = get_transaction() # magical built in function i = 0 for path, obj in objects: updater(obj) if i != 0 and not i % 100: # partial commit for ever 100 transaction.commit(1) i += 1 def updater(obj): "This updates the objects" new_default_value = '' obj.newAttr = new_default_value update('big_product', updater) regards Max M
<evolve>