[Zope] Accessing properties of broken instances

Jim Fulton jim@digicool.com
Wed, 22 Dec 1999 12:26:31 -0500


Stephen Pitts wrote:
> 
> On Mon, Dec 20, 1999 at 02:31:32PM -0600, Stephen Pitts wrote:
> > How can I access the properties of a broken Z-Class instance through
> > DTML? I've rewritten a Z-Class inside one of my Products in Python and
> > I'm trying to migrate all of the instances. I know the data is there,
> > because I can export the instance to an HTML file and the properties
> > show up. :-)
> > --
> > Stephen Pitts
> > smpitts@midsouth.rr.com
> > webmaster - http://www.mschess.org
> >
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://lists.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists -
> >  http://lists.zope.org/mailman/listinfo/zope-announce
> >  http://lists.zope.org/mailman/listinfo/zope-dev )
> >
> 
> The attached patch fixes it so that you can access properties of Broken
> instances. Why is this not default behavior?

This patch essentially undoes the __getattr__ in the broken class. This could
lead to real problems because it might allow the broken object to be
updated or saved, which could cause loss of data.

Can you restore the old class long enough to copy data to the new class?

You could get at the state from an an external method:

  def myconverter(old, new):
    hasattr(old,'a') # make sure it's state is loaded
    d={}
    d.update(old.__dict__) # now we have state
    .... copy data from the dict, d, to the new object

Jim
   

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.