[ZODB-Dev] Support for graceful ZODB Class renaming

Lalo Martins lalo@laranja.org
Wed, 5 Feb 2003 17:17:12 -0200


I know this discussion is old, but I managed to lose my zodb-dev
subscription (!) due to a mutt misconfiguration.  I'd like to throw in my
2 cents, since I encountered this very recently.

I renamed my Zope Product AltPT to OpenPT.  It had a module named
ZopePageTemplate which was also renamed to ZOPT.  I shipped the new version
with a migration package that essentially combined approaches 1 and 2:

- It defined a dummy class with the right name

- Then it patched sys.modules so that pickles of the old class would load
with the dummy class (*not* the new class)

- It added a Zope factory to the "add menu", so that, on user request, it
would traverse the zodb looking for all instances of the dummy class (via
ZopeFind) and replace them by the new class

I tried to simply poke __class__ and then setting _p_changed; it didn't
work, I don't remember why right now, so I gave up and deleted the old
objects replacing them by new ones.

The code can be seen at
http://savannah.nongnu.org/cgi-bin/viewcvs/opental/opental/OpenPTMigration/
and I have successfully ran it in many zope instances till now.

That said, it sucks :-)

> I'm inclined to go with option 2 because it is:
> 
> - Overall, it is simpler, although the conversion aspect is more
>   complicated.
> 
> - It has no risk of lost id information.

based on my experience, I tend to agree, for other reasons; transmogrifying
existing data, patching sys.modules and fooling the system can lead to
unpredictability.  I prefer to take the syste offline for a few minutes,
make a backup, run conversion *by hand* (confident on the fact that it will
report any errors to me), then bring everything back online.

"Explicit is better than implicit" and sometimes manual is safer than
automated.

[]s,
                                               |alo
                                               +----
--
            Those who trade freedom for security
               lose both and deserve neither.
--
http://www.laranja.org/                mailto:lalo@laranja.org
         pgp key: http://www.laranja.org/pessoal/pgp

Eu jogo RPG! (I play RPG)         http://www.eujogorpg.com.br/
GNU: never give up freedom                 http://www.gnu.org/