[ZODB-Dev] Re: [Zope] DateTime mess

Chris Withers chris at simplistix.co.uk
Thu Dec 1 12:21:22 EST 2005


Tim Peters wrote:
> There is only one commit in the following, so I'll assume you intended a
> second commit at the end:

yes, *sigh*, must engage brain...

>>a.someTime = DateTime()
>>get_transaction().commit()
> 
> Is `a` persistent?  I'm assuming that it is.

Yes.

>>...wait/do stuff...
>>a.someTime = DateTime()
> 
> I'm assuming another
> 
>     get_transaction().commit()
> 
> was intended here.

Yes.

>>...have we just committed a pickle containing all of 'a'?...
> 
> If `a` is persistent, yes.

If not?

>>Does mixing persistence into DateTime make a difference here?
> 
> 
> No.  Assuming `a` is persistent, you changed `a`, so `a`'s state gets
> written out.  This really has nothing to do with DateTime.  It would be the
> same answer had you done, e.g.,
> 
>     a.someTime = None
> 
> or
> 
>     a.someTime = "hi!"
> 
> or
> 
>     a.someTime = OOBTree()
> 
> instead.

*sigh* thought as much :-S

> One part is different:  if DateTime is not persistent, then the pickle for
> a's state includes the full state of a.someTime's DateTime attribute (and
> this is true for any attribute of any non-persistent type).  But if DateTime
> is persistent, then a.someTime is pickled as a distinct object, and the
> state for `a` contains only a reference to that distinct pickle (and again
> this is true for any attribute of any persistent type).  a's full state is
> pickled regardless.  The difference is in whether a's full state embeds
> a.someTime's state directly, or "points to" a distinct pickle for
> a.someTime's state.

Ah, okay, so having DateTime sublcass Persistent would only really 
matter if a had _lots_ of DateTime attributes. Does this ever happen?

> If the same DateTime object is referenced by many persistent objects, there
> can be major storage efficiencies is making DateTime persistent, because the
> "many other objects" can all point to the same pickle.  I don't know, but I
> doubt that's a likely scenario for DateTime objects.

Indeed :-/ Oh well...

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the ZODB-Dev mailing list