Re: loading an object's state

Jim Fulton <[email protected]> Fri, 12 Jul 2002 07:45:57 -0400
Newsgroups gmane.comp.python.zope.zodb4
Organization Zope Corporation
Message-ID <[email protected]>
Jeremy Hylton wrote:
> The code to unghostify an object inside the Persistent getattr hook
> looks like this:
> 
>     if ((s_name[0] != '_')
> 	|| ((strncmp(s_name, "_p_", 3) != 0)
> 	    && (strcmp(s_name, "__dict__") != 0))) {
> 	if (self->po_state == GHOST) {
> 	    self->po_state = CHANGED; 
> 	    if (_PyPersist_Load((PyPersistBaseObject *)self) == NULL) {
> 		call_p_deactivate(self);
> 		self->po_state = GHOST;
> 		return NULL;
> 	    } else
> 		self->po_state = UPTODATE;
> 	}
> 	_PyPersist_SetATime((PyPersistBaseObject *)self);
>     }
> 
> It's very similar to the code in Zope2 to accomplish the same thing.
> 
> Do you know what it changes the state from GHOST to CHANGED before
> loading the state?  The Zope2 code does the same thing.  It seems
> significant, but I can't remember (if I ever knew) why it is
> necessary.

This is to prevent the computation done in __setstate__ from
causing the object to register itself as changed.  An object
won't generate a changed event if it is already in the changed state.

Jim



-- 
Jim Fulton           mailto:[email protected]       Python Powered!
CTO                  (888) 344-4332            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org