[Zope] Changing class of objects in the ZODB

Dieter Maurer dieter at handshake.de
Mon Jun 12 14:07:07 EDT 2006


Miles Waller wrote at 2006-6-12 16:58 +0100:
>Does anyone have a good approach to changing the class of an object 
>already stored in the ZODB?

This is *very* difficult.


The main problem is that the class is usually coded (for efficiency
reasons) in the
persistent references to an object. As soon as the container
is loaded from the ZODB, a ghost is created for its persistent
reference using the class mentioned there.

This means: it is not safe to change the class of a persistent object
  unless you although modify all its containers (otherwise, some
  persistent references remain with the old class. This potentially
  leads to non-deterministic behaviour).


I usually solve you problem with proxy classes:


  When I want to refactor something, I do, but
  leave at the old place something like:

	from NewPlace import NewClass as OldClass



-- 
Dieter


More information about the Zope mailing list