[ZODB-Dev] Migrating classes in ZODB 3.5.1

Syver Enstad syver at inout.no
Wed Nov 9 09:21:04 EST 2005


Dieter Maurer wrote:

>Syver Enstad wrote at 2005-11-7 11:51 +0100:
>  
>
>>In ZODB 3.2 I can replace the _classFactory method on DB and locate the
>>renamed/moved class by other means (a lookup table that maps old module
>>classname pairs to another class in another module). If I change
>>attributes of the persistent instance it will be saved with the new
>>class name instead of the old.
>>
>>I can't get this strategy to work under 3.5.1. It seems to work okay as
>>long as I use the custom classFactory method (not _classFactory as in
>>3.2) but 3.5.1 doesn't seem to update the modulename, classname when I
>>save the instance.
>>
>>What I want to do is just update the persistent instance so that it will
>>load from the new module/ new class after I have done a one time update
>>of the database.
>>    
>>
>
>I fear this will not work.
>
>For efficiency reasons, the class designator (usually a
>module, classname tuple) is stored both in the object itself
>and in persistent references. While you will be able
>to modify the object's class the persistent references will
>only change when the containers are stored into the ZODB.
>
>  
>
Okay, so as far as I can see one has to either install a custom 
classfactory method on the DB instance that maps from old to new 
locations or hack sys.modules to refer to the new location by the old name.

What I don't like is that this will break for the following case as far 
as I see.

firstModule.First renamed ->  secondModule.Second

Some time later in the database life:
New class: firstModule.First.
Will be hidden by the machinery that hacks in secondModule.Second under 
the old name firstModule.First.


More information about the ZODB-Dev mailing list