durusmail: durus-users: Durus Change Preview
Durus Change Preview
2006-10-25
2006-10-25
2006-10-25
2006-10-25
2006-10-25
2006-10-25
2006-10-25
2006-10-25
2006-10-25
2006-10-25
2006-10-31
2006-10-31
Durus Change Preview
David Binger
2006-10-26
On Oct 26, 2006, at 9:30 AM, Patrick K. O'Brien wrote:

> 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?

There is no need for that.  Run this script, and the next time you
start,
the class of root really is Persistent.  It doesn't change the
name of the class of the root instance, it changes the actual
class of the root instance.

If you want to change the class of instances other than the root, then
you must also call x._p_note_change() on every instance whose pickle
contains a reference to any instance whose class is changing.

>
> 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.

That has always been true.  I think customizing __getstate__ and
__setstate__ on your subclasses of Persistent requires extreme care,
and should be avoided for this reason, especially for the root instance.

>
> 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__).

Right, and I decided that I liked your solution. It is very nice for
the pickles to have a portable format, and I think it is best to
stick to that except perhaps in the most extreme cases.




reply