[ZODB-Dev] Re: Coping with Class Changes

Tres Seaver tseaver at palladion.com
Mon Sep 4 14:43:29 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dieter Maurer wrote:
> Chris S wrote at 2006-9-3 15:40 -0400:
>> Is there a standard procedure for dealing with fundamental changes to
>> classes? For instance, how do you make a ZODB cope with a class being
>> renamed, or being placed in a different location? How will it know
>> that oldmod.myclass == newmod.myclass?
> 
> It does not.
> 
> You can use so called "module aliases" to partially cope
> with module relocation and "class aliases" to cope with class renaming.
> Otherwise, you have to use migration scripts that physically
> recreate the objects (and the references to it!) with the new classes.

As an example of "module aliases" (which Zope handles for its own
add-ons), you could do something like (untested)::

  # BBB for renamed module
  import new, sys
  oldmod = new.module('oldmod')
  oldmod.myclass = MyClass
  sys.modules['oldmod'] = oldmod

Class renames are simpler, often just adding the old name immediately
below the renamed class::

  class UsedToBeFoo:
      pass
  Foo = UsedToBeFoo  # BBB for renamed class


Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE/HPR+gerLs4ltQ4RAvcVAKCtLWdte6VqfLC6NO/x2wnK+S2orQCgqER6
XR+/tdjt4Z/aleFo8ZVqg2k=
=p+ki
-----END PGP SIGNATURE-----



More information about the ZODB-Dev mailing list