[Zope-dev] Persistence and __getattr__

Jim Fulton jim@digicool.com
Wed, 02 Jun 1999 16:55:21 -0400


Kent Polk wrote:
> 
> It appears to me that if you have a class object that you want to
> be Persistence, all the object attributes have to be in object.__dict__
> or Persistence.__getattr__ has no way of retrieving them.

This is right, unless you are willing to go down to the C level.
 
> This at first seems pretty obvious, but what about instances where
> your object attributes change outside of zope?

Why are these objects persistent?  If they are persistent, then 
their data is stored in Zope and doesn't change outside of
Zope.

> I can't determine
> any way to trigger an 'attribute refresh' on a __getattr__ failure
> if the attribute does not exist in the object.__dict__.

Right.
 
> Is this correct?

Yes.  It sounds like you don't want a persistent object at all.
You want an object that get's it's data from somewhere else
(somewhere other than the object database).

You can have a sub-object of a persistent object that is not persistent
and gets *it's* data from somewhere else.  This is essentially what
happens with database connections and SQL methods. 

> Is it that 'volatile' attributes cannot be Persistent?

There's no point in making them persistent, since they won't be
stored in the database. :)
 
> I see that when I try to override Persistence.__getattr__ in order
> to add the capability to create or change attributes while still
> seemingly duplicating the the method instructions, I encounter an
> infinite loop. :^)  Yes, I read the docs, but I'm trying to figure
> out if there is perhaps a way around this puzzle.

Don't override __getattr__ or __setattr__ for subclasses of Persistent.
(It *can* be done, but it requires such *deep* zen that it makes *my*
head hurt. There is actually a class used by ZClasses that does this. 
:)

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.