[Grok-dev] Persistence issue with grok.Model
Brandon Craig Rhodes
brandon at rhodesmill.org
Thu Jan 8 10:01:50 EST 2009
"Paul Wilson" <paulalexwilson at gmail.com> writes:
>>>> class C(object):
> ... a = 0
> ... def __getattribute__(*args):
> ... print "Intercepting", args
> ... return object.__getattribute__(*args)
> ...
>>>> c = C()
>>>> c.a
> Intercepting (<__main__.C object at 0x4024948c>, 'a')
> 0
>>>> c.a = 0
>>>> c.__dict__
> Intercepting (<__main__.C object at 0x4024948c>, '__dict__')
> {'a': 0}
>
> My interpretation of what you said was that the "Intercepting" line
> would be omitted from the c.__dict__ lookup.
You were correctly interpreting me, and it looks like I was wrong! The
rule as I should have stated it is:
"When object.__getattribute__ is asked for the attribute '__dict__',
then instead of looking inside the object's dictionary for the name
'__dict__' or else invoking the method __getattr__ to retrieve the
value, it short-circuits and immediately returns the object's
attribute dictionary without invoking any of the __getattr__
machinery that intercepts any other attribute."
Turning to the ZODB, I should really have perused its documentation
before trying to answer you. :-/ Take a look at:
http://svn.zope.org/ZODB/trunk/src/persistent/cPersistence.c?rev=91565&view=auto
and look at the comment above the function named "unghost_getattr". It
looks (from my cursory inspection) as though an object freshly pulled
from the ZODB is a "ghost" without object attributes, until you ask for
one of the attributes that is not in the list shown in that method.
But, as you've found already, I could be wrong. :-)
--
Brandon Craig Rhodes brandon at rhodesmill.org http://rhodesmill.org/brandon
More information about the Grok-dev
mailing list