David Binger wrote: > > On Oct 25, 2006, at 4:30 PM, David Binger wrote: > >> It isn't impossible to change the class of the root after this >> change. It is just that the recipe for doing it is a bit longer, >> and the same goes for changing the class of any persistent instance >> that uses data for slots. > > I think this recipe works, slots or not: > > > """ > Example script for changing the root class. > """ > from durus.connection import Connection > from durus.file_storage import FileStorage > from durus.persistent import Persistent > import durus.persistent_dict > > # Edit these as you like. > storage_file_name = "foo.durus" > new_class_for_root = Persistent > > if __name__ == '__main__': > # Set the class before the instance is created or loaded, > # so that we avoid possible slot layout obstacles. > durus.persistent_dict.PersistentDict = new_class_for_root > connection = Connection(FileStorage(storage_file_name")) > connection.get_root()._p_note_change() > connection.commit() That looks simple and clever. I wonder if it might make it difficult to debug if there was a problem in the new class. Perhaps combining it with a class rename so that on subsequent loads the unpickler knows the real class name? Another challenge is that you might want to change __getstate__ and __setstate__ to store something different in the pickle. Then either the new persistent class will fail to process the old pickle state, or the __setstate__ method on the new class will have to inspect the passed in state to determine if it is the "new style" state or the "old style" state. While that isn't a big deal on the single root object, it is a potentially slow operation when you have a lot of instances getting unpickled. This was the one issue I couldn't easily solve with my Schevo fork of Durus. At least, I couldn't easily solve it while maintaining compatibility with existing database files. The result is that the file on disk is bigger than it needs to be, and pickling/unpickling is probably ever-so-slightly slower since the state is "wrapped" in a dict when it doesn't need to be (since instances no longer have a __dict__). -- Patrick K. O'Brien Orbtech http://www.orbtech.com Schevo http://www.schevo.org Louie http://www.pylouie.org