[ZODB-Dev] Re: getting the object ID (_p_oid attribute)

Robert Gravina robert at gravina.com
Mon Jun 26 14:39:53 EDT 2006


On 2006/06/27, at 3:16, Florent Guillaume wrote:

> Robert Gravina wrote:
>> I've been having trouble getting the object ID of persisted  
>> objects in the ZODB. I have read that the _p_oid attribute is  
>> supposed to contain this, but when I access persisted objects from  
>> a filestore and check this value it always seems to be None.
>> Also, is there any way to get an object ID *before* an object has  
>> been persisted?
>
> You can call container._p_jar.add(yourobject) to have it get an oid  
> before commit time.
>

Thankyou! I will try that soon. I just tried loading a persisted  
object interactively and noticed that although the _p_oid doesn't  
print out as anything (and hence I always thought it was empty in my  
debugging prints), it isn't actually None! Can anyone explain this?  
(here "p" is my persisted object)

 >>> p._p_oid
'\x00\x00\x00\x00\x00\x00\x00\x08'
 >>> print p._p_oid
 >>> p._p_oid is None
False


Robert

> Florent
>
> -- 
> Florent Guillaume, Nuxeo (Paris, France)   Director of R&D
> +33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com



More information about the ZODB-Dev mailing list